From 15f43a0f6338bd7df51f550d3f736eea41ebfb01 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Aug 2026 14:55:21 +0000 Subject: [PATCH] docs: record that the reconstruction noise map is the unconstrained uncertainty reconstruction_covariance_matrix is [F + reg_coeff*H]^-1, the posterior covariance of the positive-negative (unconstrained) Warren & Dye solve. But Settings.use_positive_only_solver defaults to True, so the reconstruction is normally NNLS. Constraining s >= 0 truncates the posterior, so this overstates per-pixel uncertainty -- more so near the s = 0 boundary, and not meaningfully at all for pixels pinned at exactly zero. Documentation only; no behaviour change. The maths is left alone deliberately, because measurement showed the practical effect is small at the operating point and because the obvious "fix" is wrong. Measured on real ray-traced fits (Isothermal + shear, RectangularBilinearAdaptDensity, Constant regularization), varying the regularization coefficient and locating the Bayesian-evidence optimum that a model-fit actually converges on: at the evidence-optimal coefficient (lambda* = 10 in every case tested) r_eff 0.05: 96.6% of mesh pinned, noise overstated x1.263 median, flux 0.0% r_eff 0.10: 87.1% pinned, x1.055 median, flux -1.3% r_eff 0.30: 42.3% pinned, x1.007 median, flux 0.0% well below the evidence optimum (under-regularized): up to x2.8 median and x10 on individual pixels, with source flux through a S/N >= 5 cut moving by as much as -49%. The Bayesian evidence selects away from the regime where this matters, so for most fits the bias is small and one-directional (conservative). Also recorded: restricting the covariance to the solver's free set is NOT the correction. That treats the active set as known and so understates. The two bracket the true truncated-Gaussian posterior, and swapping one bound for the other would not be more correct. Caveat on the measurement, not repeated in the docstring: the lens mass was fixed at truth, so a real fit with a free and imperfect mass model may need a lower coefficient to absorb residuals -- which is the regime where the gap opens. Tracked in PyAutoMind draft/bug/autoarray/reconstruction_noise_map_solver_mismatch.md. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_0133X4XhMV91SFjzV2mK4Ejh --- autoarray/inversion/inversion/abstract.py | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/autoarray/inversion/inversion/abstract.py b/autoarray/inversion/inversion/abstract.py index 348fc8c60..0a5efb72f 100644 --- a/autoarray/inversion/inversion/abstract.py +++ b/autoarray/inversion/inversion/abstract.py @@ -952,6 +952,34 @@ def reconstruction_noise_map(self): conditioning-limited roundoff, measured at ~7e-15 relative at `cond ~ 1e3` rising to ~4e-5 at `cond ~ 1e13`; neither result is the more correct one. + Caveat -- this is the uncertainty of the UNCONSTRAINED solve + ------------------------------------------------------------ + `reconstruction_covariance_matrix` is `[F + reg_coeff*H]^-1`, the posterior covariance of the + positive-negative (unconstrained) solution of Warren & Dye (2003) eq. 12. But + `Settings.use_positive_only_solver` defaults to `True`, so the reconstruction is normally a + non-negative least-squares solve. Constraining `s >= 0` truncates the posterior, and a truncated + Gaussian's covariance is not the untruncated one, so this **overstates** the per-pixel uncertainty -- + by more for pixels near the `s = 0` boundary, and it is not meaningful at all for pixels the solver + pinned at exactly zero. + + The size of the discrepancy was measured on real ray-traced lens fits (`Isothermal` + shear, + `RectangularBilinearAdaptDensity`, `Constant` regularization). It depends strongly on the + regularization coefficient, and the Bayesian evidence -- which is what a model-fit maximises when + choosing that coefficient -- happens to select the regime where it is small: + + - At the evidence-optimal coefficient, this noise map is overstated by a median factor of ~1.01 + (extended source) to ~1.26 (very compact source), with individual pixels up to ~2x. Source flux + and magnification computed through a `S/N >= 5` cut moved by 0.0% to -1.3%. + - At coefficients well below the evidence optimum (an under-regularized fit) the factor grows to + ~2.8 median and ~10x on individual pixels. + + So for most fits this is a small, one-directional (conservative) bias. Treat per-pixel error bars on + a very compact source as good to a few tens of percent rather than exact, and be more careful if the + regularization coefficient came out well below its evidence optimum. + + Note that restricting the covariance to the solver's free set is **not** the correction: that treats + the active set as known and so understates. The two bracket the true truncated-Gaussian posterior. + Returns ------- The noise-map of the reconstruction as a one dimensional ndarray, which does not account for the covariance