Recency-weighted v4 model: fast-Elo blend, Team-DC majority, nightly refit
Validated on the strict 2018-2022 window and confirmed on the untouched 2022-2026 test set (RPS 0.1703 vs 0.1721 over 4,448 matches): - the Elo member now blends 30% of a 3x-faster Elo walk, so recent results move ratings much harder - ensemble weight shifts from 75/25 toward Elo to 45/55 toward the time-decayed Team-DC member — the recent-form model now leads - Team-DC refits nightly (and at boot) on the 15-year window plus every finished 2026 match, via a new committed-at-build dcTrain.json (server-only, excluded from the PWA precache) - a recent-form goal multiplier was also tested and did NOT validate; it ships disabled, and backtest.json records the whole decision buildBacktest.ts grew the experiment harness: wider xi/k grids, the fast-Elo and form variants, a pre-registered ship bar (>=0.0005 validation RPS), and a 7-day refit-cadence check. Older ratings.json files still work — all new model fields are optional with golden regression coverage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+27
-3
@@ -13,9 +13,13 @@ import { fitTeamDc, type DcMatch } from '../src/lib/model/teamDc';
|
||||
|
||||
// Ensemble hyper-params — tuned on the 2018–2022 validation window and verified
|
||||
// out-of-sample on 2022–2026 by scripts/buildBacktest.ts. Keep in sync with it.
|
||||
const TEAMDC_XI = 0.5;
|
||||
const TEAMDC_SHRINK_K = 5;
|
||||
const ENSEMBLE_W = 0.75; // log-pool weight on the Elo-DC member
|
||||
// v4 recency config: more ensemble weight on Team-DC, plus a fast Elo walk
|
||||
// (K×3) blended into the Elo member at β=0.3, so recent results count harder.
|
||||
const TEAMDC_XI = 0.25;
|
||||
const TEAMDC_SHRINK_K = 3;
|
||||
const ENSEMBLE_W = 0.45; // log-pool weight on the Elo-DC member
|
||||
const FAST_M = 3; // fast-Elo K multiplier
|
||||
const FAST_BETA = 0.3; // blend weight on the fast walk
|
||||
const FIT_WINDOW_YEARS = 15;
|
||||
|
||||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
@@ -62,6 +66,8 @@ function main(): void {
|
||||
const rows = parseCsv(readFileSync(CSV, 'utf8'));
|
||||
const elo = new Map<string, number>();
|
||||
const get = (t: string) => elo.get(t) ?? START_ELO;
|
||||
const eloFast = new Map<string, number>();
|
||||
const getFast = (t: string) => eloFast.get(t) ?? START_ELO;
|
||||
|
||||
// Calibration accumulators (modern era only).
|
||||
let sumTotal = 0, nCalib = 0;
|
||||
@@ -88,6 +94,10 @@ function main(): void {
|
||||
const delta = eloDelta(r.hs, r.as, eh, ea, k, homeAdv);
|
||||
elo.set(home, eh + delta);
|
||||
elo.set(away, ea - delta);
|
||||
const feh = getFast(home), fea = getFast(away);
|
||||
const fastDelta = eloDelta(r.hs, r.as, feh, fea, k * FAST_M, homeAdv);
|
||||
eloFast.set(home, feh + fastDelta);
|
||||
eloFast.set(away, fea - fastDelta);
|
||||
lastDate = r.date;
|
||||
}
|
||||
|
||||
@@ -126,6 +136,8 @@ function main(): void {
|
||||
}
|
||||
// Ensure every WC team has a rating (default for any never seen).
|
||||
for (const t of ALL_TEAMS) if (!(t in ratings)) ratings[t] = START_ELO;
|
||||
const ratingsFast: Record<string, number> = {};
|
||||
for (const t of Object.keys(ratings)) ratingsFast[t] = Math.round(getFast(t) * 10) / 10;
|
||||
|
||||
// ---- Team-DC ensemble member: fit on the recent window through today ----
|
||||
const nowT = new Date(lastDate).getTime();
|
||||
@@ -162,12 +174,24 @@ function main(): void {
|
||||
},
|
||||
teamDc,
|
||||
ensembleW: ENSEMBLE_W,
|
||||
ratingsFast,
|
||||
fastBeta: FAST_BETA,
|
||||
fastM: FAST_M,
|
||||
teamDcFit: { xi: TEAMDC_XI, shrinkK: TEAMDC_SHRINK_K, windowYears: FIT_WINDOW_YEARS },
|
||||
ratings,
|
||||
};
|
||||
|
||||
mkdirSync(OUT_DIR, { recursive: true });
|
||||
writeFileSync(join(OUT_DIR, 'ratings.json'), JSON.stringify(out));
|
||||
|
||||
// Compact training rows for the server's nightly in-tournament Team-DC refit
|
||||
// (absolute dates, so daysAgo can be recomputed as the tournament progresses).
|
||||
const dcRows = rows
|
||||
.filter((r) => nowT - new Date(r.date).getTime() <= windowMs)
|
||||
.map((r) => [r.date, canonicalTeam(r.home), canonicalTeam(r.away), r.hs, r.as, r.neutral ? 1 : 0]);
|
||||
writeFileSync(join(OUT_DIR, 'dcTrain.json'), JSON.stringify({ asOf: lastDate, rows: dcRows }));
|
||||
console.log(`dcTrain → public/data/dcTrain.json (${dcRows.length} rows, ${FIT_WINDOW_YEARS}y window)`);
|
||||
|
||||
const top = Object.entries(ratings).slice(0, 12).map(([t, r]) => `${t} ${Math.round(r)}`).join(', ');
|
||||
console.log(`ratings → public/data/ratings.json (${rows.length} matches, asOf ${lastDate})`);
|
||||
console.log(`params: goalsPerElo=${out.params.goalsPerElo} avgGoals=${out.params.avgGoals} rho=${rho} homeAdvElo=${HOME_ADV_ELO}`);
|
||||
|
||||
Reference in New Issue
Block a user