fix: imaging/delaunay log_evidence -inf via rank-stripped regularisation (#69)#13
Merged
Merged
Conversation
…ion block (#69) Root cause ---------- `compute_log_evidence` was computing `slogdet` on the full `regularization_matrix`, which is rank-deficient: the script's lens model includes linear MGE light profiles whose linear parameters share the inversion's linear system but are not regularised. Their rows / columns in the regularisation matrix are zero, so the full matrix is singular and `slogdet` returns -inf for log_det(H). The same applies to F + H (which is well-conditioned only when reduced). PyAutoArray's reference `Inversion.log_evidence` chain handles this correctly by computing the log-det terms on the REDUCED block — the `regularization_matrix_reduced` / `curvature_reg_matrix_reduced` properties slice the matrices down to just the mapper-pixel rows and columns (positive-definite, Cholesky-safe). See `autoarray/inversion/inversion/abstract.py::log_det_regularization_matrix_term`. Fix --- - Precompute `inversion.regularization_matrix_reduced`, `inversion.curvature_reg_matrix_reduced`, and `inversion.mapper_indices` eagerly outside the timed region. - Change `compute_log_evidence` to slice the reconstruction by `mapper_indices` for the regularisation term, and use Cholesky-based log-det on the reduced PD matrices — matching the reference implementation in `PyAutoArray.Inversion.log_det_*_term`. - chi² and the noise-normalisation term still use the full reconstruction and full noise map, since those are per-pixel data terms over the masked image, not regularised matrix terms. Validation ---------- Locally, on PyAutoLens 2026.5.14.2 / Intel i9-10885H CPU: log_evidence (step-by-step) — now finite, matches reference 26288.321397 log_evidence (inv matrices) — same log_evidence (reference) = 26288.321397 Eager regression assertion PASSED: log_evidence matches 26288.321397 Regression assertion PASSED: log_evidence matches 26288.321397 Whole script exits 0 (was exit 1 with -inf vs 26288 mismatch). Refs ---- - Bug filed at PyAutoLabs/autolens_workspace_developer#69; the upstream source-of-truth `_developer/jax_profiling/jit/imaging/delaunay.py` has the same bug. A follow-up PR there should mirror this fix. - Surfaced by today's full-script run against the canonical autolens_profiling repo (Phase 5 ship validation). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes _developer#69 —
likelihood/imaging/delaunay.pywas returninglog_evidence = -inffrom both step-by-step and inv-matrix rebuilds, whileFitImaging.log_evidencereturned a finite26288.321397. The bug was in the script's manual recomputation, not in the library.Validated end-to-end: script now exits 0, both regression assertions PASS at
26288.321397.Root cause
compute_log_evidencecomputedslogdeton the fullregularization_matrix, which is rank-deficient: the script's lens model includes linear MGE light profiles whose linear parameters share the inversion's linear system but are not regularised. Their rows / columns in the regularisation matrix are zero, so the full matrix is singular andslogdetreturns-infforlog_det(H). The same applies toF + Hif you slice through those zero rows.PyAutoArray's reference
Inversion.log_evidencechain handles this correctly by computing the log-det terms on the reduced block —regularization_matrix_reduced/curvature_reg_matrix_reducedslice the matrices down to just the mapper-pixel rows and columns (positive-definite, Cholesky-safe). Seeautoarray/inversion/inversion/abstract.py::log_det_regularization_matrix_termfor the reference implementation.Fix
inversion.regularization_matrix_reduced,inversion.curvature_reg_matrix_reduced, andinversion.mapper_indiceseagerly outside the timed region.compute_log_evidenceto:mapper_indicesfor thes^T H sregularisation term.2 * sum(log(diag(L)))) on the reduced PD matrices — matching the reference implementation.chi²and the noise-normalisation term still use the full reconstruction and full noise map, since those are per-pixel data terms over the masked image, not regularised-matrix terms.Validation
Locally on PyAutoLens 2026.5.14.2 / Intel i9-10885H CPU:
Whole script exits 0 (was exit 1 with
-infvs26288mismatch).Refs
_developer/jax_profiling/jit/imaging/delaunay.pyhas the same bug. A follow-up PR there should mirror this fix — added as a TODO note in the F1 follow-up tracking comment.autolens_profilingrepo (Phase 5 ship validation).🤖 Generated with Claude Code