@@ -185,19 +185,25 @@ n_hashes(h::LpHash) = length(h.shift)
185
185
hashtype (:: LpHash ) = Int32
186
186
187
187
# See Section 3.2 of the reference paper
188
- function single_hash_collision_probability (hashfn:: LpHash , sim:: Real )
188
+ function single_hash_collision_probability (hashfn:: LpHash , sim:: T ) where {T <: Real }
189
+ # ## If sim ≈ 0 then the integral won't be possible to numerically compute,
190
+ # ## however we know that the probability equals one.
191
+ if sim ≈ T (0 )
192
+ return T (1 )
193
+ end
194
+
189
195
# ## Compute the collision probability for a single hash function
190
196
distr, scale = hashfn. distr, hashfn. scale
191
- integral, err = quadgk (x -> pdf (distr, x/ sim) * (1 - x/ scale),
192
- 0 , scale, rtol= 1e-5 )
197
+ integral, err = quadgk (x -> pdf (distr, x/ sim) * (T ( 1 ) - x/ scale),
198
+ T ( 0 ), T ( scale) , rtol= 1e-5 )
193
199
integral = integral ./ sim
194
200
195
201
# Note that from the reference for the L^p LSH family, we're supposed to
196
202
# integrate over the p.d.f. for the _absolute value_ of the underlying
197
203
# random variable, rather than the raw p.d.f. Luckily, all of the
198
204
# distributions we have to deal with here are symmetric and centered at
199
205
# zero, so all we have to do is multiply the integral by two.
200
- single_hash_prob = integral .* 2
206
+ single_hash_prob = T ( integral .* 2 )
201
207
end
202
208
203
209
function similarity (hashfn:: LpHash )
0 commit comments