SPB Git

spb/wp26_uqo

Public
944 B · 29 lines python
1# Author: Simon-Pierre Boucher — simon-pierre.boucher@uqo.ca2"""Pre-specified stopping rule: stop when the inter-quartile range of log point estimates changes by3less than ``tol`` (relative) between consecutive rounds. Recorded in the transcript; never used to4select the best round."""5from __future__ import annotations67import math89import numpy as np1011IQR_TOL = 0.01121314def iqr_log_points(points: dict[str, float] | list[float]) -> float:15    vals = list(points.values()) if isinstance(points, dict) else list(points)16    vals = [math.log(v) for v in vals if v is not None and v > 0]17    if len(vals) < 2:18        return 0.019    q75, q25 = np.percentile(vals, [75, 25])20    return float(q75 - q25)212223def should_stop(prev_iqr: float | None, cur_iqr: float, tol: float = IQR_TOL) -> bool:24    if prev_iqr is None:25        return False26    if prev_iqr == 0.0:27        return cur_iqr == 0.028    return abs(cur_iqr - prev_iqr) < tol * prev_iqr29
Files · main
Menu

Theme