This is the section that makes the artifact useful. Below is the actual winning
train.py, byte-for-byte as committed at E0009 — the configuration
that produced the decision track's best frontier value (27.584597) and became the incumbent
for the sealed run — followed by what it does that matters, and the traps that actually
fired in this study.
train.py, verbatimMODE, CONVENTION, K, ESTIMATOR,
FAMILY, TRIM. Every computation lives in analysis.py,
the stable study library. That is what made E0003 possible: the fix that turned a
guardrail-breaching discard into the track's only KEEP was one word —
hazen → inverted_cdf — and the diff proves nothing else
changed. If the convention had been buried in the estimator module, the same fix would have
been an unfalsifiable multi-line edit.missing check
demands KLEIN_EVALUATION_KIND, KLEIN_EXPERIMENT_ID and
KLEIN_TRACK from the environment and raises with the exact remedy
(KLEIN_SMOKE=1 for a shape check) rather than defaulting. A train.py that
“works” when run by hand is a train.py that will one day produce a number with no
manifest behind it.klein run-one refuses a result
whose printed metric name does not match the track being run. Rather than discover that after a
run, analysis.MODE_TRACK[MODE] != TRACK raises immediately with a message naming
both. This is cheap defensive code that pays for itself the first time you edit
MODE and forget the --track flag.sealed_repro and sealed_decision read pre-registered published truth
and may only run under klein run-one --final-test. The file enforces both
directions: a sealed mode without --final-test raises, and
--final-test on an adaptive mode raises too (“--final-test spends
a track's one sealed access”). A single sealed access per track is a contract you cannot
un-spend, so the guard belongs where it cannot be forgotten.prepare.py and trust it thereafter. Don't: it is the only thing standing between
this study and a silent substitution of extRemes::damage's genuinely-1925–95
top-30, which looks like the same dataset, is not, and would break every published comparison
while raising no error. The gate is cheap; the failure it prevents is invisible.extra must carry every
guardrail key of the running track with its measured value —
analysis.check_extra asserts that before a mode may return, and
wall_seconds is added here because this file is the only place that knows
t0. This is study 05's lesson F1 imported as code: there, a metric that was written
to aux_metrics.tsv but not printed cost a real experiment slot.extra on every run.
"mode": MODE, "convention": CONVENTION — two strings that turn every ledger
row into a self-describing record. When section 4's detective story needed to prove that E0002
and E0003 differed only in the convention, the evidence was already in
aux_metrics.tsv; nobody had to reconstruct it from commit messages.The textbook GLS formula invites you to compute . Do not. 's condition number runs to 2.7e4 for log-Cauchy across the reported trims (against about 35 for the normal member at k = 8, (0.05, 0.95)), and it grows sharply as ; on the r = 25 validation grid it is far worse still, since the standard Cauchy density at the 0.01 quantile is ≈3e−4. The mathematically identical, numerically safe route is Cholesky whitening:
L = cholesky(Sig, lower=True)
mu, sigma = lstsq(solve_tri(L, X), solve_tri(L, Y))[0]
# and the GoF statistic uses the SAME factor - a squared norm, again no inverse
r = Y - X @ [mu, sigma]
W = n / sigma**2 * (solve_tri(L, r) ** 2).sum()
And log the condition number on every fit. The study's estimator returns
sigma_star_cond with each gQLS result, so the loop can see conditioning degrade
rather than infer it from a bad answer. E0002 and E0003 both recorded
sigma_star_cond_max = 27302.62 on the log-Cauchy family — identical across the
two conventions, which is itself evidence that the convention change moved the data
vector and not the covariance.
log-Cauchy has no finite moments. In this implementation, mean_loss() and
cte() raise NotImplementedError for such families
rather than returning a number. The ledger carries the reason as a first-class aux metric on
E0007:
moment_note: “log-Cauchy has NO finite moments:mean_loss()andcte()raiseNotImplementedErrorby design, so this family can only ever be priced through QUANTILES — any mean/CTE/TVaR number for it is a truncation artifact.”
This is the cheapest control in the study and the one most likely to matter in production. A numerical quadrature would have returned a large float that is an artefact of where it was truncated, and it would have looked exactly like an estimate. The refusal fires at the moment of misuse and converts a silent pricing error into a stack trace. Note the corollary: a moment-based robust estimator (trimmed or Winsorized moments) has nothing to trim on a family with no moments — which is precisely the gap the quantile grid fills.
This study needs two quantile conventions for two different jobs, and mixing them up costs a
guardrail breach. The implementation exports them as separately named constants —
SUMMARY_QUANTILE_METHOD (Hazen, for the descriptive identity gate) and
THESIS_QUANTILE_METHOD (inverted_cdf, for the estimators) — and
takes method= everywhere, so a pre-registered convention sweep is still possible. One
further wrinkle is exposed as quantile_space=: the thesis writes
(quantile the dollars, then log), which is identical to
quantiling the log-dollars under order-statistic conventions but not under interpolating
ones.
E0001 produced parameters inside the reporting resolution and was discarded on a
max_abs_w_deviation of 0.4940. The temptation in that moment is to widen the
guardrail, because the headline number looked fine. The correct reading is that W is
a quadratic form in the residuals and therefore far more sensitive to the exact grid than a
two-parameter regression line through it — so the insensitive quantity passing while
the sensitive one fails localizes the bug to the grid. That single discard is what sent
the study back to Chapter 2's definition and produced its only reproduction KEEP.
Every candidate description in this study's ledger states the expected metric and the expected disposition before the run: E0002's says “predicted mean ~0.0093 with max_abs_param_deviation ~0.032 BREACHING the 0.02 guardrail … discard predicted”. Two benefits, both real. A prediction that lands makes the discard informative rather than disappointing — E0002 was a deliberate measurement of a convention, not a failed attempt. And a prediction that misses is caught immediately, while the reasoning is still in your head rather than three phases later.
(family, a, b, k, quantile convention) — and the last two are usually
left to a library default. At n = 30 the convention alone moves a fitted parameter by up to
0.1040 and k by up to 0.1223: 20.8× and 24.5× the
0.005 reporting resolution. Swapping hazen for inverted_cdf is
the whole difference between a discard at 0.009303 with a breached guardrail and a keep at
0.002754. (C7)NotImplementedError is the control. (C8)About 970 lines of numpy/scipy (estimators.py 802 +
stress.py 171) covering six standard members, oQLS + gQLS + MLE, both goodness-of-fit
tests and the B = 1000 parametric bootstrap, backed by 20/20 tests in 0.69 s. The
mathematical core is about fifteen lines: grid → design matrix → known Σ★ →
Cholesky-whitened least squares. There is no released R or Python package for gQLS
— adoption means owning the code and its tests. Budget for the tests that pin your Σ★
specifically, because a wrong Σ★ fails silently and only the o2-versus-g2 split catches it.