Calibrate hits point-in-time: partial pass, and an honest ceiling of 0.667
Fitted the isotonic map on game_date < 2026-08-02 (n=589) and evaluated it on everything from that date forward (n=383). The map never saw the evaluation rows, which is the only thing that makes the result mean anything -- fitting and evaluating on the same rows always looks perfectly calibrated, because the map is reciting the answers it was built from. It works, on most of the distribution. Held-out after correction: 0.477 comes back 0.506, 0.587 comes back 0.580, 0.667 comes back 0.603 -- against raw errors of +0.191, +0.279 and +0.246 in the same bins. Ordering survived, and that was verified pairwise rather than assumed, because a broken map would silently destroy the one thing this model does well. Two findings matter more than the pass. First, the honest ceiling is 0.667. Once the numbers are truthful this model has no 80%-plus hit reads at all -- the top of its range was miscalibration, not confidence. A four-leg ticket at the ceiling is 0.198, where the raw numbers implied 0.686. The high-floor parlay is a two-thirds-per-leg proposition, and that is the number to say out loud. Second, calibration is certified BY BAND rather than by a blanket flag. Held-out error was -0.029 and +0.007 through the middle but -0.167 at the bottom and +0.063 at the top: the model is trustworthy over most of its mass and untrustworthy at both edges. A single true/false would either throw away the 72% that works or ship the edges that do not. Only a probability inside a certified band is marked stackable, and that flag is what chainAcross requires before it will compound anything. The certified band is 0.40 to 0.60, n=276. A methodological catch on the way: my first pass condition demanded honest bins at 0.70 and above -- but honest calibration REMOVES those bins, since the ceiling drops to 0.667. The gate would have failed the repair for succeeding. It now tests the highest remaining band instead of a fixed threshold. Wired forward with the same discipline: calibrationService fits strictly before today, splits by time rather than at random, and returns null on thin history so that "no calibrator" means nothing is stackable rather than "trust the raw numbers". p_win is never mutated -- the calibrated value rides beside it as p_win_calibrated, because a calibration map is a correction to a forecast, not a different forecast, and the counter stays byte-identical. 4,275 tests green (339 suites); web build exit 0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W1sivYNqY2TS5ftykmHBU9
This commit is contained in:
@@ -136,6 +136,79 @@ describe('PROPAGATION — one settled result improves every reading that shares
|
||||
});
|
||||
});
|
||||
|
||||
describe('CALIBRATION SERVICE — fit past, apply forward, certify by band', () => {
|
||||
const svc = require('../../src/services/model/calibrationService');
|
||||
|
||||
/** Rows dated so the time-split is meaningful. */
|
||||
const hist = (specs) => {
|
||||
const out = [];
|
||||
let day = 1;
|
||||
for (const [p, n, rate] of specs) {
|
||||
for (let i = 0; i < n; i += 1) {
|
||||
// Wins are INTERLEAVED, not front-loaded. Front-loading makes the
|
||||
// outcome correlate with the date, so a time-split would train on the
|
||||
// wins and certify on the losses — the generator would be creating the
|
||||
// very leakage the split exists to prevent.
|
||||
const won = Math.floor((i + 1) * rate) > Math.floor(i * rate) ? 1 : 0;
|
||||
out.push({ p, won, date: `2026-07-${String(day).padStart(2, '0')}` });
|
||||
if (out.length % 40 === 0) day = Math.min(28, day + 1);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
it('refuses to build on thin history rather than passing raw numbers through', () => {
|
||||
// "No calibrator" must mean nothing is stackable, never "trust the model".
|
||||
expect(svc.build(hist([[0.6, 50, 0.5]]))).toBeNull();
|
||||
expect(svc.build([])).toBeNull();
|
||||
});
|
||||
|
||||
it('corrects an over-confident model and marks the corrected value calibrated', () => {
|
||||
// Claims 0.9, realises 0.6 — the shape measured on real hits.
|
||||
const c = svc.build(hist([[0.5, 300, 0.5], [0.9, 300, 0.6]]), { minBin: 30 });
|
||||
expect(c).not.toBeNull();
|
||||
const out = c.calibrate(0.9);
|
||||
expect(out.p_calibrated).toBeLessThan(0.75); // the 0.9 claim is corrected down
|
||||
expect(out.p_raw).toBe(0.9);
|
||||
});
|
||||
|
||||
it('a probability OUTSIDE a certified band is not stackable', () => {
|
||||
const c = svc.build(hist([[0.5, 300, 0.5], [0.9, 300, 0.6]]), { minBin: 30 });
|
||||
const far = c.calibrate(0.02);
|
||||
// Whatever it maps to, if the band was never certified it cannot compound.
|
||||
if (!far.calibrated) expect(far.reason).toBe('outside_certified_band');
|
||||
});
|
||||
|
||||
it('an absent probability is absent, never 0', () => {
|
||||
const c = svc.build(hist([[0.5, 300, 0.5], [0.9, 300, 0.6]]), { minBin: 30 });
|
||||
const out = c.calibrate(null);
|
||||
expect(out.p_calibrated).toBeNull();
|
||||
expect(out.calibrated).toBe(false);
|
||||
});
|
||||
|
||||
it('splits by TIME — the certification window is later than the fit window', () => {
|
||||
const c = svc.build(hist([[0.5, 300, 0.5], [0.9, 300, 0.6]]), { minBin: 30 });
|
||||
expect(c.certified_through >= c.fitted_through).toBe(true);
|
||||
expect(c.fit_n).toBeGreaterThan(0);
|
||||
expect(c.certify_n).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('END TO END: uncalibrated legs are refused; calibrated ones compound', () => {
|
||||
const c = svc.build(hist([[0.5, 300, 0.5], [0.9, 300, 0.6]]), { minBin: 30 });
|
||||
const legs = ['a', 'b'].map((id) => {
|
||||
const v = c.calibrate(0.5);
|
||||
return { id, p: v.p_calibrated, calibrated: v.calibrated, gameId: `g${id}` };
|
||||
});
|
||||
const out = chain.chainAcross(legs);
|
||||
if (legs.every((l) => l.calibrated)) {
|
||||
expect(out.ok).toBe(true);
|
||||
expect(out.compound_probability).toBeCloseTo(legs[0].p * legs[1].p, 3);
|
||||
} else {
|
||||
expect(out.reason).toBe('uncalibrated_atoms');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('CALIBRATION — the gate itself', () => {
|
||||
const rows = (spec) => spec.flatMap(([p, n, hitRate]) =>
|
||||
Array.from({ length: n }, (_, i) => ({ p, won: i < Math.round(n * hitRate) ? 1 : 0 })));
|
||||
|
||||
Reference in New Issue
Block a user