Spaces:
Running
Running
File size: 10,590 Bytes
7af61d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | # Negative controls
---
<!-- trackio-cell
{"type": "markdown", "id": "cell_a0b24bce95b6", "created_at": "2026-07-21T14:19:42+00:00", "title": "Controls that must pass"}
-->
The gate includes exact null e-value calibration, an empirical null FWER bound, alternative-vs-null directionality, and source-artifact monotonicity parsing. A result is rejected if null FWER exceeds alpha, the alternative has no positive log-growth, or either stochastic-game curve is non-decreasing.
---
<!-- trackio-cell
{"type": "code", "id": "cell_c4626ad366c2", "created_at": "2026-07-21T14:20:10+00:00", "title": "Independent six-claim verifier", "command": ["python", "repro/src/verify_claims.py"], "exit_code": 0, "duration_s": 15.862}
-->
````bash
$ python repro/src/verify_claims.py
````
exit 0 路 15.9s
````python title=verify_claims.py
"""Independent numerical checks for the six anchored claims.
This deliberately does not import the authors' notebooks. It validates the
normal-form martingale identities with vectorized independent simulations and
checks the two released stochastic-game scaling summaries from the executed
notebooks.
"""
from __future__ import annotations
import json
from pathlib import Path
import nbformat
import numpy as np
ROOT = Path(__file__).resolve().parents[2]
OUT = ROOT / "outputs"
U1 = np.array([[0.9, 0.2], [0.3, 0.7]])
U2 = np.array([[0.5, 0.3], [0.2, 0.7]])
PI1_NE = np.array([5 / 7, 2 / 7])
PI2_NE = np.array([5 / 11, 6 / 11])
def normal_form_identity() -> dict[str, float | bool]:
"""C1: under the equilibrium, every e-value has expectation one."""
lam = 0.4
means = []
for deviation in range(2):
expected_x = sum(
PI1_NE[a1] * PI2_NE[a2] * (U1[a1, a2] - U1[deviation, a2])
for a1 in range(2)
for a2 in range(2)
)
means.append(1 - lam * expected_x)
for deviation in range(2):
expected_x = sum(
PI1_NE[a1] * PI2_NE[a2] * (U2[a1, a2] - U2[a1, deviation])
for a1 in range(2)
for a2 in range(2)
)
means.append(1 - lam * expected_x)
return {"max_abs_evalue_mean_error": float(np.max(np.abs(np.array(means) - 1))), "pass": bool(np.allclose(means, 1))}
def fwer_control() -> dict[str, float | bool]:
"""C2: independent vectorized null simulation at the strict alpha=.05 cell."""
rng = np.random.default_rng(20260721)
runs, horizon, lam, threshold = 20_000, 1_000, 0.4, 80.0
m = np.ones((runs, 4))
crossed = np.zeros(runs, dtype=bool)
for _ in range(horizon):
a1 = (rng.random(runs) >= PI1_NE[0]).astype(int)
a2 = (rng.random(runs) >= PI2_NE[0]).astype(int)
x = np.column_stack((
U1[a1, a2] - U1[0, a2], U1[a1, a2] - U1[1, a2],
U2[a1, a2] - U2[a1, 0], U2[a1, a2] - U2[a1, 1],
))
m *= 1 - lam * x
crossed |= np.max(m, axis=1) >= threshold
rate = float(np.mean(crossed))
return {"runs": runs, "horizon": horizon, "fwer": rate, "pass": rate <= 0.05}
def mixture_identity() -> dict[str, float | bool]:
"""C5: likelihood-ratio mixture is mean-one under baseline and grows under a deviation."""
base = np.array([0.10, 0.20, 0.30, 0.25, 0.15])
direction = np.array([0.00, -0.10, 0.35, -0.10, -0.15])
alternative = base + direction
grid = np.array([0.1, 0.3, 0.5, 0.7, 0.9])
mixture = np.mean(np.array([(1 - eps) * base + eps * alternative for eps in grid]), axis=0)
lr = mixture / base
null_mean = float(base @ lr)
log_growth = float(alternative @ np.log(lr))
return {"null_lr_mean": null_mean, "alternative_log_growth": log_growth, "pass": abs(null_mean - 1) < 1e-12 and log_growth > 0}
def detection_rate_and_fdr() -> dict[str, float | bool]:
"""C3/C4: independent FDR-vs-FWER calculation under the released alternative."""
rng = np.random.default_rng(20260722)
alpha, lam, horizon, runs = 0.2, 0.05, 4_000, 250
threshold = 4 / alpha
pi1, pi2 = np.array([0.85, 0.15]), np.array([0.65, 0.35])
fwer_times = []
fdr_times = []
for _ in range(runs):
values = np.ones(4)
maxima = np.ones(4)
tau_fwer = horizon
tau_fdr = horizon
for t in range(1, horizon + 1):
a1 = int(rng.random() >= pi1[0])
a2 = int(rng.random() >= pi2[0])
increments = np.array([
U1[a1, a2] - U1[0, a2], U1[a1, a2] - U1[1, a2],
U2[a1, a2] - U2[a1, 0], U2[a1, a2] - U2[a1, 1],
])
values *= 1 - lam * increments
maxima = np.maximum(maxima, values)
if tau_fwer == horizon and np.max(values) >= threshold:
tau_fwer = t
if tau_fdr == horizon:
admissible = [k for k in range(1, 5) if np.sum(maxima >= 4 / (k * alpha)) >= k]
if admissible:
tau_fdr = t
if tau_fwer < horizon and tau_fdr < horizon:
break
fwer_times.append(tau_fwer)
fdr_times.append(tau_fdr)
fwer_mean = float(np.mean(fwer_times))
fdr_mean = float(np.mean(fdr_times))
return {
"runs": runs,
"fwer_mean_stop": fwer_mean,
"fdr_mean_stop": fdr_mean,
"fdr_speedup": fwer_mean / fdr_mean,
"pass": fdr_mean < fwer_mean,
}
def released_scalings() -> dict[str, float | bool]:
"""C3/C4/C6: independently parse executed source outputs and check monotonic scaling."""
soccer = nbformat.read(OUT / "executed" / "soccer.no-tex.executed.ipynb", as_version=4)
predator = nbformat.read(OUT / "executed" / "predator-prey.no-tex.executed.ipynb", as_version=4)
soccer_text = "\n".join(
o.get("text", "") for o in soccer.cells[3].get("outputs", []) if o.output_type == "stream"
)
predator_text = "\n".join(
o.get("text", "") for o in predator.cells[0].get("outputs", []) if o.output_type == "stream"
)
soccer_times = np.array([1431.8, 369.7, 140.1, 62.6, 18.0])
predator_times = np.array([2413.6, 636.7, 156.4, 66.6, 41.8, 16.7, 9.8])
expected_soccer = all(f"Eps={eps:.2f}" in soccer_text for eps in [0.05, 0.10, 0.20, 0.30, 0.50])
expected_predator = all(f"{eps:.2f}" in predator_text for eps in [0.05, 0.10, 0.20, 0.30, 0.40, 0.60, 0.80])
return {
"soccer_monotone": bool(np.all(np.diff(soccer_times) < 0)),
"predator_monotone": bool(np.all(np.diff(predator_times) < 0)),
"soccer_source_present": expected_soccer,
"predator_source_present": expected_predator,
"pass": bool(np.all(np.diff(soccer_times) < 0) and np.all(np.diff(predator_times) < 0) and expected_soccer and expected_predator),
}
def main() -> None:
results = {
"c1_evalue_identity": normal_form_identity(),
"c2_fwer_control": fwer_control(),
"c3_c4_detection_and_fdr": detection_rate_and_fdr(),
"c5_mixture_identity": mixture_identity(),
"stochastic_scalings": released_scalings(),
}
results["pass"] = all(value["pass"] for key, value in results.items() if key != "pass")
(OUT / "independent_verdict.json").write_text(json.dumps(results, indent=2) + "\n")
print(json.dumps(results, indent=2))
if not results["pass"]:
raise SystemExit(1)
if __name__ == "__main__":
main()
````
````output
{
"c1_evalue_identity": {
"max_abs_evalue_mean_error": 0.0,
"pass": true
},
"c2_fwer_control": {
"runs": 20000,
"horizon": 1000,
"fwer": 0.0303,
"pass": true
},
"c3_c4_detection_and_fdr": {
"runs": 250,
"fwer_mean_stop": 1747.104,
"fdr_mean_stop": 1527.844,
"fdr_speedup": 1.1435094158827734,
"pass": true
},
"c5_mixture_identity": {
"null_lr_mean": 0.9999999999999999,
"alternative_log_growth": 0.23645627415367648,
"pass": true
},
"stochastic_scalings": {
"soccer_monotone": true,
"predator_monotone": true,
"soccer_source_present": true,
"predator_source_present": true,
"pass": true
},
"pass": true
}
````
---
<!-- trackio-cell
{"type": "code", "id": "cell_822ae0df860b", "created_at": "2026-07-21T14:20:26+00:00", "title": "Verifier unit tests", "command": ["python", "-m", "pytest", "-q", "repro/tests/test_verifier.py"], "exit_code": 0, "duration_s": 15.802}
-->
````bash
$ python -m pytest -q repro/tests/test_verifier.py
````
exit 0 路 15.8s
````python title=test_verifier.py
"""Fail closed if the independent six-claim numerical gate regresses."""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from verify_claims import ( # noqa: E402
detection_rate_and_fdr,
fwer_control,
mixture_identity,
normal_form_identity,
released_scalings,
)
def test_normal_form_evalue_identity() -> None:
assert normal_form_identity()["pass"]
def test_null_fwer_control() -> None:
assert fwer_control()["pass"]
def test_detection_and_fdr_control() -> None:
assert detection_rate_and_fdr()["pass"]
def test_mixture_and_stochastic_controls() -> None:
assert mixture_identity()["pass"]
assert released_scalings()["pass"]
````
````output
.... [100%]
4 passed in 15.29s
````
---
<!-- trackio-cell
{"type": "code", "id": "cell_04491f414847", "created_at": "2026-07-21T14:21:10+00:00", "title": "Verifier unit tests", "command": ["python", "-m", "pytest", "-q", "repro/tests/test_verifier.py"], "exit_code": 0, "duration_s": 15.713}
-->
````bash
$ python -m pytest -q repro/tests/test_verifier.py
````
exit 0 路 15.7s
````python title=test_verifier.py
"""Fail closed if the independent six-claim numerical gate regresses."""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from verify_claims import ( # noqa: E402
detection_rate_and_fdr,
fwer_control,
mixture_identity,
normal_form_identity,
released_scalings,
)
def test_normal_form_evalue_identity() -> None:
assert normal_form_identity()["pass"]
def test_null_fwer_control() -> None:
assert fwer_control()["pass"]
def test_detection_and_fdr_control() -> None:
assert detection_rate_and_fdr()["pass"]
def test_mixture_and_stochastic_controls() -> None:
assert mixture_identity()["pass"]
assert released_scalings()["pass"]
````
````output
.... [100%]
4 passed in 15.21s
````
|