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)
| 22 | |
| 23 | # 利用fp与fn计算最佳的参数 |
| 24 | def _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 | |
| 44 | def _random_name(length): |
no test coverage detected