MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / _optimal_param

Function _optimal_param

join/LSH/datasketch/lsh.py:24–41  ·  view source on GitHub ↗

Compute the optimal `MinHashLSH` parameter that minimizes the weighted sum of probabilities of false positive and false negative.

(threshold, num_perm, false_positive_weight,
        false_negative_weight)

Source from the content-addressed store, hash-verified

22
23# 利用fp与fn计算最佳的参数
24def _optimal_param(threshold, num_perm, false_positive_weight,
25 false_negative_weight):
26 '''
27 Compute the optimal `MinHashLSH` parameter that minimizes the weighted sum
28 of probabilities of false positive and false negative.
29 '''
30 min_error = float("inf")
31 opt = (0, 0)
32 for b in range(1, num_perm+1):
33 max_r = int(num_perm / b)
34 for r in range(1, max_r+1):
35 fp = _false_positive_probability(threshold, b, r)
36 fn = _false_negative_probability(threshold, b, r)
37 error = fp*false_positive_weight + fn*false_negative_weight
38 if error < min_error:
39 min_error = error
40 opt = (b, r)
41 return opt
42
43
44def _random_name(length):

Callers 1

__init__Method · 0.70

Calls 2

Tested by

no test coverage detected