in reply to [OT] The statistics of hashing.

How to calculate those odds for each new hash, as the number of hashes already set into the vectors increases?

Update: Following figure is not right. (Corrected figure provided in following post.)

IIUC it's just (N/4294967296)**4, where N is the number of MD5 hashes that have already been entered into the bit vector.
But that's assuming that MD5 hashes distribute evenly, and I don't know if that has been established (or disproved). If they don't distribute evenly, then the odds of hitting a false positive will increase.

Not sure what affect your "Bloom Filters" variation would have.


Replies are listed 'Best First'.
Re^2: [OT] The statistics of hashing.
by syphilis (Archbishop) on Mar 31, 2012 at 23:55 UTC
    IIUC it's just (N/4294967296)**4

    I believe the figure I should have provided is:
    (1 - ((4294967295/4294967296) ** N)) ** 4

    And if that's not right, I give up.

    Update: The logic is simple. (Danger, Will Robinson ;-)
    If you're picking numbers at random in the range (1 .. 4294967296), then the probability that the N+1th pick has already come up is:
    1 minus the probability that it has *not* already come up
    and the probability that it has *not* already come up is (4294967295/4294967296) ** N

    So that gives us the
    1 - ((4294967295/4294967296) ** N)

    But because we're looking for the case where all *4* numbers have already come up, that probability needs to be raised to the 4th power ... which yields the final figure.


      Thanks syphilis. Your calculations make sense to me. But I'm not sure that it gels with the actual data?

      Assuming I've coded your formula correctly (maybe not!), then using 10 hashes & vectors, I get the odds of having seen a dup after 1e9 inserts as (1 - ((4294967295/4294967296)**1e9) ) **10 := 0.00000014949378123.

      By that point I had actually seen 13 collisions:

      And looking at the figure for 4e9 := 0.00667569553892502, by which time the 10 vectors will be almost fully populated, it looks way too low to me?

      I would have expected that calculation (for N=4e9) to have yielded odds of almost 1?

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I get the odds of having seen a dup after 1e9 inserts as (1 - ((4294967295/4294967296)**1e9) ) **10 := 0.00000014949378123

        That's not the probability of "having seen a dup", but the probability that the 1000000001st random selection of 10 numbers would be reported as a dup (ie the probability that each of the relevant bits in all 10 bit vectors was already set for that 1000000001st random selection of the 10 numbers).

        If I get a chance I'll try to work out the probability of "having seen a dup" in the first 1e9 iterations. (But, judging by some of the figures being bandied about, it probably has little bearing on this actual case where we're looking at MD5 hashes instead of random selections.)