Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Comparing two arrays

by sundialsvc4 (Monsignor)
on Dec 16, 2013 at 18:07 UTC ( #1067358=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Comparing two arrays
in thread Comparing two arrays

It is, at best, very rude to say “total garbage” in response to a post ... it doesn’t make you look like a genius, merely a boor.   (I searched the entire thread for the word “best” and did not find it.   Perhaps your eyes are better than mine.)

That being said, i-f the requirement is for “a matching entry,” then the technique that I described will work extremely well.   Strictly speaking, yes, it is possible for (say) a hash-collision to occur, but with a strong algorithm like SHA1 it basically isn’t going to happen.

Any exploitable “predictable fact” about the actual data can be profitably used to reduce the search-space, and (IMHO) in a situation such as this, pragmatically must be.   Even something as basic as “the total number of 1’s” can be pressed into service.   If you can “reasonably predict” that the differences between the searched-for array and the “best fit” that will be found will consist, let’s say, of a change-of-state of no more than (some) n positions, then even a brute-force search could be limited to consider only the candidates which fall into that range, perhaps starting with any exact-matches and then working outward x for x in (1..n).   This does, of course, open up the possibility of a statistical Type-2 Error (concluding that no best-match exists when in fact one does), but this might be judged to be either acceptable or necessary.   (Or not ...)

If necessity really must become the mother of invention, and once again if you know that there are exploitable characteristics of the data, it is also possible to apply hashing or ones-counting to slices of the total vector.   Instead of merely counting all the 1’s, count them in every (say) thousand bits.   Apply some useful heuristic to this vector of sums to decide whether you choose to examine the whole thing.

In the end, the problem won’t be completely-abstract, nor will be its solution.   There must be something, in the real world, that stipulates what is and what is not “best,” or even “plausible.”   It’s my opinion that you must solve this problem, at least in significant part, by reducing the total number of vectors that you consider, and by selecting for consideration only those which are “most likely.”   Representational optimizations such as the use of bit-vectors may also be important, but even these can’t be applied in a brute-force way.   You’ll simply never get the work done.


Comment on Re: Comparing two arrays

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067358]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-09-02 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (18 votes), past polls