feat: real validation framework (Phase 2 v1) - #40
Open
Tilanthi wants to merge 1 commit into
Open
Conversation
…idence gate Replaces rigged adapter scores with genuine, reproducible statistics so evidence reflects held-out reality, not a planted answer. Pure standard library (no numpy/scipy) — stays inside the Phase-0 runtime constraint. - src/sapiens/validation.py: regularized incomplete beta (Lentz continued fraction) as the backbone; exact Clopper-Pearson binomial CI; Pearson correlation with two-sided p-value; Benjamini-Hochberg FDR (essential when a discovery loop tests many candidates); leakage-safe holdout_split; PassPolicy + evaluate() gate that decides pass/fail from real statistics. - src/sapiens/adapters/regression.py: SyntheticRegressionAdapter that evaluates candidates via genuine held-out Pearson r and p-value through the gate — not a planted score. - tests: numerical correctness vs analytic Beta CDFs and known CI/p-value/FDR values, plus regression-adapter climb and wrong-direction-rejection tests. Notable behaviour: a candidate whose correlation is significant but in the WRONG direction fails on effect size (point below min_effect) even though its p-value is tiny — the gate rejects p-value-hunting. Phase 0 invariants hold: synthetic data, real methodology, scientific_discoveries_claimed stays 0. ruff + pytest green (28 tests). Co-Authored-By: Claude <noreply@anthropic.com>
Tilanthi
added a commit
to Tilanthi/SAPIENS
that referenced
this pull request
Jul 20, 2026
…lidation framework) # Conflicts: # src/sapiens/adapters/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The first piece of Phase 2: a real statistical validation framework that replaces the adapters' rigged scores with genuine, reproducible evidence — so pass/fail reflects held-out reality, not a planted answer. Pure standard library (no numpy/scipy), staying inside the Phase-0 runtime constraint.
Why
Phase 0 adapters deliberately return planted scores to exercise the pipeline. Before any real adapter (Phase 4) can be trusted, the system needs honest statistics: confidence intervals, p-values, and — critically for a discovery loop that tests many candidates — multiple-comparison correction. This PR builds that machinery and demonstrates it flowing through the existing kernel/ledger/ladder.
Changes
src/sapiens/validation.py— the framework:holdout_split;PassPolicy+evaluate()— a gate that decides pass/fail from real statistics (point estimate, CI floor, p-value).src/sapiens/adapters/regression.py—SyntheticRegressionAdapterthat evaluates each candidate via a genuine held-out Pearson test through the gate, not a planted score.Notable behaviour
A candidate whose correlation is significant but in the wrong direction fails on effect size (
point -0.988 below min_effect 0.5) even though its p-value is ~1e-49. The gate deliberately rejects p-value-hunting — a "significant" result that contradicts the hypothesis is not evidence for it.Verified:
proportion_ci(8, 10)→ [0.4439, 0.9748];betaimatches Beta(1,1)/Beta(2,2)/Beta(0.5,0.5) CDFs exactly; BH on [0.01,0.04,0.03,0.20] → [0.04, 0.0533, 0.0533, 0.20].Phase 0 invariants
Synthetic data, real methodology,
scientific_discoveries_claimedstays 0.validation.pyis a core module (statistics only; claims nothing).ruffclean,pytest→ 28 passed.Scope note
This is Phase 2 v1 (the statistical foundation). Not included here: calibration reports, leakage-control fixtures beyond
holdout_split, and the structured L3 review panels (Phase 3) that consume this real evidence. Real adapters (Phase 4) remain gated behind the licensing/clean-room wall.🤖 Generated with Claude Code