in reply to Search for identical substrings
I've posted code here that seems to be about 7000 times faster than BrowserUk's solution result posted here and therefore about 3 million times faster than OP's original code.
The six strings provided in bioMan's scratchpad were used as the test set with the same match result as BrowserUk's in about 0.01 seconds. Note that the claimed match position given in BrowserUk's result is wrong (checked by a manual examination of the data), but the match length is right.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Search for identical substrings
by BrowserUk (Patriarch) on Aug 21, 2005 at 07:14 UTC | |
I've posted code here that seems to be about 7000 times faster than BrowserUk's solution
All that said, your algorithm is blazingly fast and the anomolies can probably be corrected. If so, or if bioman only needs the single LCS, and can live with specifying a minimum match and arranging for his input data to always be a multiple of that minimum size, it blow's what I have into dust. At least, until I can adapt my code to use elements of your search technique :). Nice++ Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] [select] |
by GrandFather (Saint) on Aug 21, 2005 at 09:06 UTC | |
Actually the code does generate all the LCS's. I used to print those out. If you are interested you can add back the line by copying the print for best match, pasting it after the line $localBest = expandMatch (@$localBest); and replacing $bestMatch with $localBest. The run time remains about the same :). I noticed the anomolies, but was so excited by the run rate that I sort of forgot about them and posted the code. The problem will be in the expandMatch sub which does a binary search to extend the match at each end to the full extent of the matched run. It's probably trivial to fix and I'll have a look and update the posted code when I find the bug. The minimum match length is where the "blazingly fast" bit comes from. Although it still seems to be pretty fast even for small match lengths. This turned out so much faster than anything else that I couldn't quite believe it! I'm pleased that you have reproduced my results (bugs included). Perl is Huffman encoded by design. | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Aug 21, 2005 at 23:18 UTC | |
The thing that really slowed my code down was detecting multiple, equal-length LCS within the same pairing. Eg. In this dataset:
my program detects and reports both the As at the beginning and the Ts at the end:
Where your program will only report the first of the two equal LCSs:
Also, if the equal LCSs appear in different relative positions within the pairing, which is reported depends upon which appears first within the first string of the pairing:
I cannot see how you could adapt your code to handle that without loosing it's performance? This may be just a bug-report rather than a fundemental problem, but I modified the above dataset by deleting one of the As from the start of each line and adding two T's (keeping the length to 64) at the end, making the Ts the LCS for the pair. Ignoring the reporting anomolies, your code still detects the As as the LCS unless I drop the minimum length right down to 2?
Indeed, as it stands, your code always favours a shorter match in the first string over a longer match in the second unless the minimum match is set to a value less than or equal to the difference between the matches. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] [select] |
|
Re^2: Search for identical substrings
by BrowserUk (Patriarch) on Aug 21, 2005 at 02:37 UTC | |
Note that the claimed match position given in BrowserUk's result is wrong (checked by a manual examination of the data), but the match length is right. The offsets were all +10 because I failed to remove the sequence labels from the strings. This is now corrected. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
| [reply] [d/l] |