mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 10:34:23 +01:00
Add optimization study O06: does a staged evaluation ladder (cheap diagnostics, a development battery, then full evaluation) save total cost without rejecting useful candidates? - Arms: full evaluation of every candidate (bounded reference), a development-only ladder, and a ladder with a stage-0 score; usefulness is decided only by full evaluation with every collateral endpoint. - Stage-0 scores must earn their role: predictor quality (Spearman, AUC) is reported, and separability or KL never substitutes for task success. - Extra development samples use an anytime-valid mixture test (or a single fixed-sample look); naive repeated peeking is refused. Null simulations: 0.0245 and 0.0405 at alpha 0.05 against 0.24 for peeking. - A seeded audit sample of exclusions is fully evaluated and every exclusion is reported. Rules are digest-bound; confirmation-exposed, test and confirmation rows are refused. - Verdict is "no improvement" unless every seed passes cost, false-rejection, task and collateral tolerances with an unchanged confirmation candidate. `obliteratus experiments screening`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
66 lines
3.0 KiB
Python
66 lines
3.0 KiB
Python
"""Stage-1 decision procedures of calibrated screening: error guarantees under peeking.
|
|
|
|
Null simulations at ``p = p0``: the anytime-valid mixture martingale and the
|
|
single-look fixed-sample test keep the rejection rate within ``alpha`` plus
|
|
three Monte Carlo standard errors, while re-checking a fixed-sample Wilson
|
|
interval after every batch exceeds it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import math
|
|
|
|
import pytest
|
|
|
|
from obliteratus.analysis.screening_sequential import (
|
|
decide, log_evidence, run_sequence, simulate_null,
|
|
)
|
|
|
|
pytestmark = pytest.mark.cpu
|
|
ALPHA = 0.05
|
|
REPS = 2000
|
|
BOUND = ALPHA + 3 * math.sqrt(ALPHA * (1 - ALPHA) / REPS)
|
|
|
|
|
|
@pytest.mark.parametrize("method", ["mixture-martingale", "fixed-sample"])
|
|
def test_valid_procedures_hold_alpha_on_null_simulations(method):
|
|
found = simulate_null(method, p0=0.5, alpha=ALPHA, batch=4, max_rows=120,
|
|
repetitions=REPS, seed=1)
|
|
assert found["looks"] == 30 and found["rejection_rate"] <= BOUND
|
|
assert found["nominal_bound_holds"]
|
|
# Above the floor (the composite null) the error is smaller still.
|
|
above = simulate_null(method, p0=0.5, true_rate=0.6, alpha=ALPHA, repetitions=500, seed=2)
|
|
assert above["rejection_rate"] <= BOUND
|
|
|
|
|
|
def test_naive_repeated_peeking_exceeds_alpha():
|
|
found = simulate_null("naive-peeking", p0=0.5, alpha=ALPHA, batch=4, max_rows=120,
|
|
repetitions=REPS, seed=1)
|
|
assert found["rejection_rate"] > BOUND and not found["nominal_bound_holds"]
|
|
|
|
|
|
def test_sequential_test_has_power_and_stops_early():
|
|
found = simulate_null("mixture-martingale", p0=0.5, true_rate=0.1, repetitions=300, seed=3)
|
|
assert found["rejection_rate"] > 0.95
|
|
decision, rows, successes = run_sequence("mixture-martingale", [False] * 40, p0=0.5,
|
|
alpha=ALPHA, batch=4, max_rows=40)
|
|
assert decision == "reject" and rows < 16 and successes == 0
|
|
decision, rows, _ = run_sequence("mixture-martingale", [True] * 40, p0=0.5, alpha=ALPHA,
|
|
batch=4, max_rows=40)
|
|
assert decision == "promote" and rows < 16
|
|
decision, rows, _ = run_sequence("fixed-sample", [False] * 40, p0=0.5, alpha=ALPHA,
|
|
batch=4, max_rows=40)
|
|
assert decision == "reject" and rows == 40
|
|
|
|
|
|
def test_evidence_and_decisions_are_well_defined():
|
|
reject, promote = log_evidence(0, 0, 0.3)
|
|
assert reject == pytest.approx(0.0, abs=1e-9) and promote == pytest.approx(0.0, abs=1e-9)
|
|
assert decide("mixture-martingale", 3, 6, p0=0.5, alpha=ALPHA, max_rows=6) == "promote"
|
|
assert decide("fixed-sample", 0, 3, p0=0.5, alpha=ALPHA, max_rows=6) == "continue"
|
|
assert decide("naive-peeking", 10, 10, p0=0.5, alpha=ALPHA, max_rows=10) == "promote"
|
|
with pytest.raises(ValueError, match="strictly between"):
|
|
log_evidence(1, 1, 1.0)
|
|
with pytest.raises(ValueError, match="Unknown stage-1 method"):
|
|
decide("bayes", 1, 2, p0=0.5, alpha=ALPHA, max_rows=4)
|