Expand description
Analytic diagnostic helpers for LAML/REML optimization.
Production diagnostics inspect analytic invariants only. Runtime fitting, prediction, and diagnostic APIs must consume quantities the optimizer already computes. This module implements diagnostic strategies that identify root causes of gradient pathologies from those analytic quantities:
-
KKT Audit (Envelope Theorem Check): Detects violations of the stationarity assumption used in implicit differentiation.
-
Spectral Bleed Trace: Detects when truncated eigenspace corrections are inconsistent with the penalty’s energy in that subspace.
-
Dual-Ridge Consistency Check: Verifies that the ridge used by the inner solver (PIRLS) matches what the outer gradient calculation assumes.
Structs§
- Classification
Prediction Metrics - Production classification scores computed from one prediction vector.
- Diagnostic
Config - Configuration for gradient diagnostics
- Dual
Ridge Result - Result of dual-ridge consistency check
- Envelope
Audit - Result of envelope theorem (KKT) audit
- Gradient
Diagnostic Report - Complete diagnostic report for a gradient evaluation
- Prediction
Diagnostics - Residual diagnostics for observed values and predicted means.
- Spectral
Bleed Result - Result of spectral bleed trace diagnostic
Enums§
- KktRefusal
Diagnosis - Three-way classification of why the cert refused, computed from the
H_pen spectrum and the projected residual at the refusing iterate.
RankDeficientHPenis the regression canary the nullspace lead’s smooth-construction rework is intended to eliminate; keep this variant intact when extending — it doubles as the user-facing signal for “an unconstrained polynomial null space slipped past absorption.”
Constants§
- DEFAULT_
CALIBRATION_ BINS - Number of equal-width probability bins in the bundled expected-calibration error diagnostic.
- DEFAULT_
GAUSSIAN_ SCALE_ FLOOR - Smallest standard deviation used by the bundled Gaussian score panel.
- DEFAULT_
PROBABILITY_ CLIP - Probability clipping used by the bundled classification diagnostic panel. Individual log-loss and Nagelkerke APIs accept an explicit clipping value; this named policy keeps the combined Rust/Python diagnostic contract in one core location.
- MIN_
EIG_ DIAG_ EVERY - Repeat period within a magnitude bucket for the Hessian-minimum-eigenvalue diagnostic: after the first emission for a bucket, every Nth subsequent invocation also emits.
- MIN_
EIG_ DIAG_ THRESHOLD - Threshold below which a positive Hessian minimum eigenvalue is treated as nearly-singular and routed through the rate-limited diagnostic.
Statics§
- H_
MIN_ EIG_ LOG_ BUCKET - Rate-limited diagnostic for Hessian minimum eigenvalue warnings
- H_
MIN_ EIG_ LOG_ COUNT - Count of
should_emit_h_min_eig_diaginvocations that have ever been considered for emission; used together withH_MIN_EIG_LOG_BUCKETto rate-limit one diagnostic per decade-magnitude bucket and perMIN_EIG_DIAG_EVERYrepeats within the same bucket.
Functions§
- auc_
from_ predictions - Tie-aware Mann-Whitney AUC. Observations greater than
0.5are the positive class, matching the package’s binomial response convention. - binary_
log_ loss_ from_ predictions - Mean Bernoulli log loss with a caller-selected probability clip.
- brier_
from_ predictions - Mean squared probability error.
- classification_
metrics_ from_ predictions - The package’s standard classification diagnostic panel.
- compute_
dualridge_ check - Check consistency between the ridge used in different stages of computation.
- compute_
envelopeaudit - Compute the inner KKT residual to detect envelope theorem violations.
- diagnostics_
from_ predictions - Compute prediction residual diagnostics from observed values and predicted means.
- expected_
calibration_ error_ from_ predictions - Equal-width-bin expected calibration error.
- format_
top_ abs - Diagnostic formatter shared across the outer optimizer and the custom-family
fitter: shows the
max_itemsentries ofvalueswith largest absolute value, formatted aslabel=[i:value, ...]. - gaussian_
log_ loss_ from_ predictions - Gaussian negative log predictive density, allowing either one shared standard deviation or one per observation.
- nagelkerke_
r_ squared_ from_ log_ likelihoods - Nagelkerke’s rescaling of Cox-Snell R² from model/null log likelihoods.
Returns
Nonewhen the null normalization is undefined. - nagelkerke_
r_ squared_ from_ predictions - Nagelkerke R² for binomial predictions against an explicit null mean.
- precision_
recall_ auc_ from_ predictions - Trapezoidal area under the precision-recall curve. Equal predicted scores enter as one threshold group, so row order within a tie cannot change the score.
- should_
emit_ h_ min_ eig_ diag - Rate-limited check for Hessian minimum eigenvalue diagnostics. Returns true if this eigenvalue warrants a diagnostic message.
- weighted_
auc_ from_ predictions - Weighted tie-aware Mann-Whitney AUC. Each positive/negative pair carries
weight
w_positive * w_negative;Noneis exactly the unit-weight score.