Thibaut Forest Claude Opus 5 (1M context) commited on
Commit ·
2a6a86a
1
Parent(s): 9d114fd
CV v5 fidelity pass (user): GroupKFold with deployment-exact held-out semantics
Browse filesFold fits on TRAIN buildings' full closed history (= the static foreign fit
deployment-legal for held-out fleets); planner state = submit.py static-path
knobs exactly, incl. the cold-start floor gate (structurally inert at fold
sizes >= 60 deaths vs gate 20); in-fold purge dropped (stricter than the
deployment it represents, bought no public coherence). Both public and
private splits are ~2x held-out fleets (Docker rehearsal) -> ONE CV for both.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1234567891011121314151617181951 unmodified lines7172737475767782 unmodified lines1601611621631641651661671681698 unmodified lines1781791801811821831841851861871889 unmodified lines19819920020120220320420520620720820921021121221311 unmodified lines225226227228229230"""THE CV (user directive 2026-08-22 v4): building-GroupKFold x temporal purge.ONE protocol lives here, deliberately. Buildings are assigned to K folds,stratified on battery-failure count and location (travel centrality). Foreach fold, for each of the 48 scenario times: fit on the TRAIN buildings'pairs whose 42d label windows lie ENTIRELY outside the scenario window(origin + W <= T or origin >= T + W - the label-overlap purge), then planthe TEST buildings as a STANDALONE fleet and evaluate its cost.THE SCORE is the mean over folds of the fold's mean scenario cost.Double holdout, no tuning: the fit never sees the test buildings (fleetaxis) AND never sees the scenario's own window (time axis). Coherence withthe public board is CHECKED against the recorded public deltas, neverfitted - a calibrated pricing layer was explicitly rejected (user,2026-08-22): an instrument tuned to reproduce past public deltas can onlyconfirm what it was tuned to.Why this protocol (2026-08-22, the day the temporal purge fell):51 unmodified lines# frontier): plain logbag / tsroute alpha 0.8 + break-even top-up, censor-# aware pricing. Frontier dials exist in submit.py for explicit A/B only.CHAMPION = dict(model='logbag', planner='tsroute', p_star=0.8, day_q=0.05,ec_margin=0.8, ec_pmax=25.0, split_days=7)N_FOLDS = 582 unmodified linesdef run_bgkf(dataset_path=Path('dataset'), kind=None, variant='base',blend=None, n_folds=N_FOLDS, origins=range(48)):"""THE SCORE. For each fold, per scenario: fit on the TRAIN buildings'purged pairs (label windows fully outside the scenario window), thenplan the TEST buildings as a standalone fleet and evaluate. Floor off(harness minimalism; the deployed floor is a submit.py concern).Candidate hooks: `kind` swaps the model family (mc.MODELS key orSklearnRUL spec), `variant` the feature set, `blend`=(kind2, w2) avalue-preserving rank blend (order changes, the primary's p42 values8 unmodified linesfolds, dev_b = build_folds(t, ctx, dataset_path, k=n_folds)t_bldg = t['device_id'].map(dev_b)p = mc.plan_tsroutep.alpha, p.p_be, p.floor_day, p.p_conf = CHAMPION['p_star'], 0.0, 0, 0.5p.ec_margin, p.ec_pmax = CHAMPION['ec_margin'], CHAMPION['ec_pmax']p.split_days = CHAMPION['split_days']p.floor_scale, p.recent_deaths = 0.0, 0.0def _fit(k_, train):hazard = k_ in ('aft', 'dthaz', 'dthaz_aux', 'logbag_open',9 unmodified linesrecs = []for f in range(n_folds):test_b = set(folds.index[folds == f])fold_train = closed[~t_bldg.loc[closed.index].isin(test_b)]for idx in origins:c = ctx[idx]T = c['start_time']# the purge, inside the fold: train pairs' label windows must lie# entirely before or after the scenario windowtrain = fold_train[(fold_train['origin'] + W <= T)| (fold_train['origin'] >= T + W)]model = _fit(kind, train)partner = _fit(blend[0], train) if blend is not None else Nonefleet = c['locs'][c['locs']['building'].isin(test_b)]rows = (t[t['origin_idx'] == idx].set_index('device_id').reindex(fleet['battery']).dropna(subset=['v_last']))11 unmodified linespred['p42'] = pd.Series(vals, index=r.sort_values(ascending=False).index).reindex(pred.index)plan = mc.plan_tsroute(pred, None, locs, T, CHAMPION['day_q'],travel_costs=c['travel_costs'],settings=c['settings'])12345678910111213141516171819202122232451 unmodified lines767778798081828382 unmodified lines1661671681691701711721731741758 unmodified lines1841851861871881891901911921931941951961979 unmodified lines20720820921021121221321421521621721821911 unmodified lines231232233234235236237238239240241242243244245246"""THE CV (user directive 2026-08-22 v5): building-GroupKFold, deployment-faithful.ONE protocol lives here, deliberately. Buildings are assigned to K folds,stratified on battery-failure count and location (travel centrality). Foreach fold: ONE fit on the TRAIN buildings' full closed-pair history (that isexactly what the deployed held-out path does - a foreign fleet's labels wereall known when the submission was built, so "before and after" isdeployment-legal, not a leak), then for each of the 48 scenario times theTEST buildings are planned as a STANDALONE fleet with the DEPLOYMENT-EXACTplanner state (submit.py's static-path knobs, including the cold-startfloor gate, which is structurally inert here because every fold trains on60+ unique deaths vs the gate's 20) and costed by the real evaluator.THE SCORE is the mean over folds of the fold's mean scenario cost.Fidelity pass (v5): this harness is the closest possible local twin of theheld-out deployment path - both public and private splits are ~2x unseenfleets served by that path (Docker dress rehearsal, phase 27). Coherencewith the public board is CHECKED against recorded public deltas, neverfitted (a calibrated pricing layer was explicitly rejected). The in-foldpurge (v4) was dropped: it made the CV stricter than the deployment itrepresents and bought no public coherence (identical sign flips).Why this protocol (2026-08-22, the day the temporal purge fell):51 unmodified lines# frontier): plain logbag / tsroute alpha 0.8 + break-even top-up, censor-# aware pricing. Frontier dials exist in submit.py for explicit A/B only.CHAMPION = dict(model='logbag', planner='tsroute', p_star=0.8, day_q=0.05,ec_margin=0.8, ec_pmax=25.0, split_days=7,floor_scale=2.5, floor_gate=20) # submit.py FLOOR_* defaultsN_FOLDS = 582 unmodified linesdef run_bgkf(dataset_path=Path('dataset'), kind=None, variant='base',blend=None, n_folds=N_FOLDS, origins=range(48)):"""THE SCORE. Per fold: one fit on the TRAIN buildings' full closed-pairhistory (deployment-exact for a held-out fleet), then per scenario theTEST buildings are planned as a standalone fleet under submit.py'sstatic-path planner state (incl. the cold-start floor gate) and costed.Candidate hooks: `kind` swaps the model family (mc.MODELS key orSklearnRUL spec), `variant` the feature set, `blend`=(kind2, w2) avalue-preserving rank blend (order changes, the primary's p42 values8 unmodified linesfolds, dev_b = build_folds(t, ctx, dataset_path, k=n_folds)t_bldg = t['device_id'].map(dev_b)# deployment-exact planner state: exactly the attributes submit.py's# static path sets, everything else at models_cv module defaults# (p_be=0, floor_day=0, p_conf=0.5 - deployment does not touch them)p = mc.plan_tsroutep.alpha = CHAMPION['p_star']p.ec_margin, p.ec_pmax = CHAMPION['ec_margin'], CHAMPION['ec_pmax']p.split_days = CHAMPION['split_days']p.floor_scale, p.recent_deaths = CHAMPION['floor_scale'], 0.0def _fit(k_, train):hazard = k_ in ('aft', 'dthaz', 'dthaz_aux', 'logbag_open',9 unmodified linesrecs = []for f in range(n_folds):test_b = set(folds.index[folds == f])train = closed[~t_bldg.loc[closed.index].isin(test_b)]model = _fit(kind, train)partner = _fit(blend[0], train) if blend is not None else Nonetrain_uniq = int(train.loc[train['dies42'] == 1, 'device_id'].nunique())for idx in origins:c = ctx[idx]T = c['start_time']fleet = c['locs'][c['locs']['building'].isin(test_b)]rows = (t[t['origin_idx'] == idx].set_index('device_id').reindex(fleet['battery']).dropna(subset=['v_last']))11 unmodified linespred['p42'] = pd.Series(vals, index=r.sort_values(ascending=False).index).reindex(pred.index)# cold-start floor, gated exactly as submit.py: observable# recent deaths / voltage-zone census, armed only when the fit# saw < floor_gate unique deaths (inert at fold sizes >= 60)p.recent_deaths = 0.0if CHAMPION['floor_scale'] > 0 and train_uniq < CHAMPION['floor_gate']:recent = int(((eol > T - W) & (eol <= T)).sum())zone = int(((rows['days_below_245'] >= 0)& (rows['days_below_245'] <= WINDOW_DAYS)& (rows['staleness'] <= 7)).sum())p.recent_deaths = float(max(recent, zone))plan = mc.plan_tsroute(pred, None, locs, T, CHAMPION['day_q'],travel_costs=c['travel_costs'],settings=c['settings'])
batteryswap_example/cv.py+41-25