nx_estimator_diagnostics.nx
buildroot/runtime/nx_estimator_diagnostics.nx
about
nx_estimator_diagnostics.nx -- substrate primitive for bias-variance
decomposition of estimator outputs.
THEORY (cited from first principles, NOT folklore):
For an estimator T̂ of a true parameter θ, the Mean Squared Error
decomposes as:
MSE(T̂) = E[(T̂ - θ)²] = Var(T̂) + [Bias(T̂)]²
where Bias(T̂) = E[T̂] - θ and Var(T̂) = E[(T̂ - E[T̂])²].
Source: Lehmann & Casella, "Theory of Point Estimation" 2nd ed.,
Springer 1998, eqs. 1.5.1, 1.5.2. Same decomposition appears in
every statistics textbook (Casella-Berger §7.3, Wasserman §6.3).
Interpretation for an HLL-vs-DS comparison:
- If our mean_err > DS mean_err but our max_err < DS max_err,
we have HIGHER BIAS but LOWER VARIANCE. The math says we should
debias the estimator. Fix class: FX11 RecalibrateTable, or
post-hoc bias correction term.
- If our mean_err < DS mean_err but our max_err > DS max_err,
we have LOWER BIAS but HIGHER VARIANCE. Add ensemble averaging
(HIP estimator) or shrinkage.
- If both worse: estimator class is fundamentally weaker; consider
algorithm swap (FX02).
Beyond the first two moments, we expose:
- skewness: (third central moment) / sigma³ -- detects asymmetric error
- excess kurtosis: (fourth central moment) / sigma⁴ - 3 -- detects
heavy tails (matters for max-error comparison)
All computed in i64 fixed-point at PPB (parts per billion) precision.
genealogy_id: lehmann_casella_1998 + pearson_skewness_1895
lineage_id: estimator_theory + moment_method
dependencies 2 imports · 3 importers
imports: syscalls.nxnx_i128.nx
imported by: nx_estimator_diagnostics_test.nxnx_remedy.nxnx_remedy_test.nx
structs
| 49 | struct EstimatorDiag |
consts
| 46 | const NX_DIAG_PPB_SCALE: i64 = 1000000000 |
| 122 | const NX_DIAG_VERDICT_BOTH_WORSE: i64 = 0 |
| 123 | const NX_DIAG_VERDICT_BOTH_BETTER: i64 = 1 |
| 124 | const NX_DIAG_VERDICT_HIGHER_BIAS_LOWER_VAR: i64 = 2 |
| 125 | const NX_DIAG_VERDICT_LOWER_BIAS_HIGHER_VAR: i64 = 3 |
| 126 | const NX_DIAG_VERDICT_TIE: i64 = 4 |
| 169 | const NX_DIAG_FX_NO_ACTION: i64 = 0 |
| 170 | const NX_DIAG_FX_SWAP_ALGORITHM: i64 = 2 // FX02 |
| 171 | const NX_DIAG_FX_REFORMULATE: i64 = 6 // FX06 |
| 172 | const NX_DIAG_FX_UPGRADE_Q: i64 = 9 // FX09 |
| 173 | const NX_DIAG_FX_RECALIBRATE: i64 = 11 // FX11 |
| 175 | const NX_DIAG_FX_ENSEMBLE: i64 = 13 // FX13 (new class) |
functions
| 59 | func nx_diag_alloc() -> *EstimatorDiag |
| 79 | func nx_diag_compute(d: *EstimatorDiag, estimates: *i64, n: i64, theta: i64) -> i64 |
| 128 | func nx_diag_compare(ours: *EstimatorDiag, theirs: *EstimatorDiag) -> i64 |
| 177 | func nx_diag_recommend(verdict: i64) -> i64 called by 1: main |