i have tricky problem need align peaks of 2 arrays. wouldn't "tricky", in case 1 shorter other, , shorter 1 can segmented. also, solution cannot have overlapping segments. illustrate, here 2 vectors zero-aligned (this isn't "real" case, per se, demonstrate idea):
and here (roughly) how i'd align them:
you can imagine, of course, multiple solutions possible - it's search optimization problem - i.e., find spacing produces optimal fit.
i have method segmentation works acceptably well, , have method evaluating positions prioritizes contour , difference between peaks (i.e., rather overall difference), appropriate use case.
the first alignment algorithm made greedy, , though solved example problem, realize in cases (possibly many!) fail account segments, since it run out of room shift into before accounting them all. can see have try multiple positions, evaluate them, , pick best one, i'm trying avoid having test many... 1 approach apply technique post: https://math.stackexchange.com/a/1787380, layout spaces between segments according partitions of integer (i.e., length difference of original vectors). but, example problem, difference 10, means trying 2 ^ (10-1) = 512 possible arrangements, think bit heavy application.
any thoughts (techniques, heuristics) appreciated. i'm working in swift, that's not important detail.
update: so, following lead of @templatetypedef (sequence alignment, dynamic programming), managed pretty good. alignment matrix filled out according to:
where:
and both s , q have been normalized [0,1]. doing hand, this:
pretty good! so, @templatetypedef pointing me in right direction.
it's worth noting, though, isn't "compact", in scaling vectors, building original matrix, extracting path, , re-formatting final sequences require fair bit of iteration. on other hand, previous idea have scaling, segmentation, calculating spacing permutations, aligning , evaluating, picking optimal one, , formatting result... bonus of method, of course, it's established, and take care of case s , q equal lengths (which pretty major bonus).
i can figure out implementation, if has tips, feel free comment.
update
i did notice "gap penalty" of -1 high, given calculation of "match" score. able decent results in number of cases -0.5.
Comments
Post a Comment