Skip to content

fix: imaging/delaunay log_evidence -inf via rank-stripped regularisation (#69)#13

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/fix-69-delaunay-log-evidence
May 16, 2026
Merged

fix: imaging/delaunay log_evidence -inf via rank-stripped regularisation (#69)#13
Jammy2211 merged 1 commit into
mainfrom
feature/fix-69-delaunay-log-evidence

Conversation

@Jammy2211

Copy link
Copy Markdown
Contributor

Summary

Fixes _developer#69likelihood/imaging/delaunay.py was returning log_evidence = -inf from both step-by-step and inv-matrix rebuilds, while FitImaging.log_evidence returned a finite 26288.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_evidence computed 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 if you slice through those zero rows.

PyAutoArray's reference Inversion.log_evidence chain handles this correctly by computing the log-det terms on the reduced block — regularization_matrix_reduced / curvature_reg_matrix_reduced 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 for the reference implementation.

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 s^T H s regularisation term.
    • Use Cholesky-based log-det (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:

  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

  • 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 — added as a TODO note in the F1 follow-up tracking comment.
  • Surfaced by today's full-script run against the canonical autolens_profiling repo (Phase 5 ship validation).

🤖 Generated with Claude Code

…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>
@Jammy2211 Jammy2211 merged commit 8299f92 into main May 16, 2026
1 check failed
@Jammy2211 Jammy2211 deleted the feature/fix-69-delaunay-log-evidence branch May 16, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: jit/imaging/delaunay.py — log_evidence rebuild returns -inf vs FitImaging's finite 26288.32

1 participant