plastic / experiments /exp4_compose /aggregate_lib.py
dmontgomery40's picture
Sync from DMontgomery40/plastic via hub-sync (part 2)
423a77c verified
Raw History Blame Contribute Delete
305 Bytes
import math
def wilson(k: int, n: int, z: float = 1.96):
if n == 0:
return (float("nan"), float("nan"))
p = k / n
den = 1 + z * z / n
c = (p + z * z / (2 * n)) / den
h = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / den
return (max(0.0, c - h), min(1.0, c + h))