accelmo.analysis.degeneracy_checker¶
Detect degenerate (unconstrained) knob directions before optimising.
Background¶
A weighted least-squares fit min_x Σ w r(x)² is well-posed only if the
measurement constrains every knob combination. Otherwise the Gauss-Newton normal
matrix A = JᵀWJ (J the residual Jacobian, W the inverse-variance
weights) is rank-deficient or ill-conditioned, with near-zero eigenvalues whose
eigenvectors are knob combinations the data cannot constrain. An optimiser started
on such a problem has no unique minimum: the knobs drift along the flat direction
with little change in loss.
A is the matrix already accumulated for parameter uncertainties
(accelmo.fitting.uncertainty.hessian_uncertainties()). Its eigenspectrum at
the initial knobs identifies a degenerate fit, and the knob combinations
responsible, before optimisation, so the user can regularise, remove knobs or add
independent data.
Unit scaling¶
The raw A mixes knobs of different physical scale (dipole k0, quad k1,
pt), so its condition number reflects unit disparity as well as degeneracy. By
default the analysis uses the symmetrically scaled matrix
à = D^{-1/2} A D^{-1/2} with D = diag(A). It is dimensionless with unit
diagonal for every constrained knob, so a small eigenvalue indicates an
unconstrained combination rather than a small-valued knob. Knobs with zero
sensitivity (diag(A) == 0) are reported separately as fully unconstrained.
- class accelmo.analysis.degeneracy_checker.DegenerateDirection(eigenvalue, relative_eigenvalue, components, contributions=list())[source]¶
Bases:
objectOne near-null direction of the normal matrix - an unconstrained combination.
- Variables:
eigenvalue (
float) – Scaled eigenvalue (≈ 0for a perfectly flat direction).relative_eigenvalue (
float) –eigenvalue / largest eigenvalue; the size of this direction’s curvature relative to the best-constrained direction.components (
ndarray) – Combination coefficients in knob space, one per knob, unit-norm. The knobs trade off alongΣ components[i] * knob[i].contributions (
list[tuple[str,float]]) –(knob_name, coefficient)pairs for the knobs that dominate this direction, largest|coefficient|first.
- Parameters:
eigenvalue (float)
relative_eigenvalue (float)
components (numpy.ndarray)
contributions (list[tuple[str, float]])
- eigenvalue: float¶
- relative_eigenvalue: float¶
- components: ndarray¶
- contributions: list[tuple[str, float]]¶
- class accelmo.analysis.degeneracy_checker.DegeneracyReport(knob_names, scaled, eigenvalues, eigenvectors, condition_number, numerical_rank, n_degenerate, degenerate_directions, zero_sensitivity_knobs, uncertainties, rel_tol)[source]¶
Bases:
objectResult of
analyse_degeneracy().- Variables:
knob_names (
list[str]) – Knob ordering matching every per-knob array below.scaled (
bool) – Whether the eigen-analysis used the unit-scaled matrix.eigenvalues (
ndarray) – Eigenvalues of the (scaled) normal matrix, descending.eigenvectors (
ndarray) – Corresponding eigenvectors as columns, in knob space and aligned witheigenvalues.condition_number (
float) –λ_max / λ_minover the positive eigenvalues;infwhen any direction is exactly flat.numerical_rank (
int) – Number of eigenvalues aboverel_tol * λ_max.n_degenerate (
int) –len(knob_names) - numerical_rank- the number of unconstrained knob combinations.degenerate_directions (
list[DegenerateDirection]) – The near-null directions, weakest first.zero_sensitivity_knobs (
list[str]) – Knobs whose data sensitivity is (numerically) zero.uncertainties (
dict[str,float]) – Physical 1σ uncertainty per knob from the raw matrix.rel_tol (
float) – Relative tolerance used for the rank decision.
- Parameters:
knob_names (list[str])
scaled (bool)
eigenvalues (numpy.ndarray)
eigenvectors (numpy.ndarray)
condition_number (float)
numerical_rank (int)
n_degenerate (int)
degenerate_directions (list[DegenerateDirection])
zero_sensitivity_knobs (list[str])
uncertainties (dict[str, float])
rel_tol (float)
- knob_names: list[str]¶
- scaled: bool¶
- eigenvalues: ndarray¶
- eigenvectors: ndarray¶
- condition_number: float¶
- numerical_rank: int¶
- n_degenerate: int¶
- degenerate_directions: list[DegenerateDirection]¶
- zero_sensitivity_knobs: list[str]¶
- uncertainties: dict[str, float]¶
- rel_tol: float¶
- property is_degenerate: bool¶
True when at least one knob combination is unconstrained by the data.
- accelmo.analysis.degeneracy_checker.analyse_degeneracy(normal_matrix, knob_names, *, scale=True, rel_tol=DEFAULT_REL_TOL, contribution_threshold=0.1, zero_sensitivity_rel=DEFAULT_ZERO_SENSITIVITY_REL)[source]¶
Diagnose unconstrained knob directions from a Gauss-Newton normal matrix.
- Parameters:
normal_matrix (
ndarray) – The weighted normal matrixA = JᵀWJ(symmetric, positive semi-definite), as accumulated by the tracking workers. Evaluate it at the initial knobs to diagnose the problem before optimising.knob_names (
list[str]) – Names of the knobs, in the row/column order ofnormal_matrix.scale (
bool) – If True (default), analyse the dimensionless symmetrically scaled matrixD^{-1/2} A D^{-1/2}so the verdict reflects collinearity rather than unit disparity between knobs.rel_tol (
float) – A direction is “unconstrained” when its eigenvalue is belowrel_tol * λ_max.contribution_threshold (
float) – A knob is listed as contributing to a degenerate direction when|coefficient| >= contribution_threshold * max|coeff|.zero_sensitivity_rel (
float) – A knob is treated as having zero sensitivity when its diagonal entry is belowzero_sensitivity_rel * max(diag).
- Return type:
- Returns:
- Raises:
ValueError – If
normal_matrixis not square orknob_namesdoes not match its dimension.- Parameters:
normal_matrix (numpy.ndarray)
knob_names (list[str])
scale (bool)
rel_tol (float)
contribution_threshold (float)
zero_sensitivity_rel (float)