accelmo.fitting.uncertainty¶
Knob uncertainties from the normal matrix A (and noise matrix B) of a fit.
- accelmo.fitting.uncertainty.covariance(matrix, *, min_eigenvalue=HESSIAN_MIN_EIGENVALUE)[source]¶
Covariance
A⁻¹of a physical normal matrix: symmetrised, eigenvalues floored tomin_eigenvalue.- Return type:
ndarray- Parameters:
matrix (numpy.ndarray)
min_eigenvalue (float)
- accelmo.fitting.uncertainty.warn_if_singular(normal_matrix, knob_names=None, *, rel_tolerance=SINGULAR_REL_TOLERANCE)[source]¶
Warn when the data normal matrix
JᵀWJis (near-)singular; returns the number of weak directions.The matrix is first scaled to unit diagonal (a correlation matrix), so the test does not depend on the knobs’ units. Directions with an eigenvalue below
rel_tolerancex the largest one are not constrained by the data: the fit returns whatever the prior or the starting point puts there, and the reported uncertainties are only as good as the prior. Pass the matrix without any prior added.- Return type:
int- Parameters:
normal_matrix (numpy.ndarray)
knob_names (list[str] | None)
rel_tolerance (float)
- accelmo.fitting.uncertainty.sandwich_uncertainties(normal_matrix, noise_matrix, *, min_eigenvalue=HESSIAN_MIN_EIGENVALUE)[source]¶
1-sigma uncertainties
sqrt(diag(A⁻¹ B A⁻¹)).Invariant to a common scale of the loss weights (
A ∝ w,B ∝ w²).- Return type:
ndarray- Parameters:
normal_matrix (numpy.ndarray)
noise_matrix (numpy.ndarray)
min_eigenvalue (float)
- accelmo.fitting.uncertainty.hessian_uncertainties(normal_matrix, *, min_eigenvalue=HESSIAN_MIN_EIGENVALUE)[source]¶
1-sigma parameter uncertainties from a Gauss-Newton normal matrix.
normal_matrixmust be the weighted normal matrixA = JᵀWJbuilt with physical inverse-variance weightsW = 1/σ²(units1/measurement²). Its inverse is then the parameter covariance andsqrt(diag(A⁻¹))gives the 1-sigma uncertainties in real parameter units - so callers must pass the un-normalised, true-variance Hessian, never one rescaled by an arbitrary loss-normalisation (which would put the result in a meaningless space).Note the factor-of-2 convention: for a chi-square
Σ w r²the second derivative is2 JᵀWJ; passA = JᵀWJhere (half that), i.e. the normal matrix / Fisher information, not the raw chi-square Hessian.The matrix is symmetrised and its eigenvalues floored to
min_eigenvalueso weakly-constrained or rank-deficient directions yield large-but-finite, non-negative uncertainties rather than blowing up or turning negative through accumulated numerical noise.- Return type:
ndarray- Parameters:
normal_matrix (numpy.ndarray)
min_eigenvalue (float)