Spaces:
Sleeping
Sleeping
Download src/protocol/elsh_params.py from acpr123/FuzzyPSI-hamming: direct link, hf CLI and curl.
- Browser
- Download file 602 Bytes
-
https://huggingface.co/spaces/acpr123/FuzzyPSI-hamming/resolve/main/src/protocol/elsh_params.py
- Command line
-
hf download hf://spaces/acpr123/FuzzyPSI-hamming/src/protocol/elsh_params.py
-
curl -L -o elsh_params.py https://huggingface.co/spaces/acpr123/FuzzyPSI-hamming/resolve/main/src/protocol/elsh_params.py
602 Bytes
| from __future__ import annotations | |
| import math | |
| def collision_probability(d: int, delta: int, k: int) -> float: | |
| denom = math.comb(d, k) | |
| total = 0.0 | |
| for r in range(0, min(k, delta) + 1, 2): | |
| total += math.comb(delta, r) * math.comb(d - delta, k - r) / denom | |
| return total | |
| def recommended_params(d: int, delta: int, lam: int = 40) -> tuple[int, float, int]: | |
| k = math.ceil(d / (delta + 1)) | |
| p_delta = collision_probability(d, delta, k) | |
| p_delta = min(max(p_delta, 1e-9), 1.0 - 1e-9) | |
| l_min = math.ceil(lam / (-math.log2(1.0 - p_delta))) | |
| return k, p_delta, l_min | |