"""Print the (b, r) that datasketch's MinHashLSH picks for given thresholds.

Requires datasketch 2.0.0 (pip install datasketch==2.0.0).  The function
_optimal_param in datasketch/lsh.py minimises
  w_fp * integral_0^t P(s) ds + w_fn * integral_t^1 (1 - P(s)) ds,
with P(s) = 1 - (1 - s^r)^b and default weights (0.5, 0.5).
"""
from importlib.metadata import version

from datasketch.lsh import _optimal_param

print(f"# datasketch {version('datasketch')}, num_perm=128, weights=(0.5, 0.5)")
print("# threshold b r b*r  P(s=threshold)  s_half")
for t in (0.5, 0.7, 0.8, 0.9):
    b, r = _optimal_param(t, 128, 0.5, 0.5)
    p_at_t = 1 - (1 - t**r) ** b
    s_half = (1 - 0.5 ** (1 / b)) ** (1 / r)   # s where P(s) = 1/2
    print(f"{t:.1f} {b} {r} {b * r} {p_at_t:.4f} {s_half:.4f}")
