Skip to content

feat: MaternSparse sparse Matérn (SPDE) precision regularization (phase 2 of #638) - #650

Merged
Jammy2211 merged 2 commits into
mainfrom
feature/matrix-free-interferometer-phase2
Oct 21, 2026
Merged

Jammy2211 merged 2 commits into
mainfrom
feature/matrix-free-interferometer-phase2

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #646. Phase 2 of #638. Community proposal: PyAutoLabs/.github#39 (@HRSAstro), reference snippet section 3.

Summary

New aa.reg.MaternSparse(coefficient, scale, nu=1.0, weights=None): the Matérn regularization as a sparse precision for rectangular meshes via the SPDE form (Lindgren, Rue & Lindström 2011). For ν = 1 (α = 2): H = coefficient · c · W⁻¹ L² W⁻¹ with L = κ² I − ∇² (5-point Laplacian with per-axis pixel scales, reflecting edges), κ = √(2ν)/scale, and c = eᵀL⁻²e so the centre variance is 1 (K(0) = 1 as for the dense kernel). It returns the sparse H (regularization_matrix_sparse_from) and its factor R = √c L W⁻¹ (regularization_factor_sparse_from, for phase 3's probe draws), the dense H on today's path (regularization_matrix_from, so it is a drop-in in an ordinary inversion), an exact log-det from the sparse LU of L, and sᵀHs. Non-rectangular meshes and ν ≠ 1 raise NotImplementedError. Mesh pixel ordering verified row-major from the top-left on RectangularUniform and the adapt-density mesh. Dense MaternKernel untouched. No priors config (fit wiring is phase 5).

API Changes

Additive only: aa.reg.MaternSparse and regularization.matern_sparse.rectangular_laplacian_sparse_from.
See full details below.

Test Plan

  • test_autoarray/inversion/regularizations/test_matern_sparse.py (14 tests): hand-built 4×3 mesh L and c (neighbours found from coordinates, independent of index arithmetic) equal the class's sparse matrix; SPD; log-det vs np.linalg.slogdet (2.5e-14 measured, 1e-10 tolerance; 4×3, 7×8, weighted); coefficient scaling; weights path = W⁻¹ c L² W⁻¹ by hand; Delaunay raises; ν ≠ 1 raises; centre variance 1 and monotonic decay along a row; subprocess no-JAX import.
  • test_matrix_free_util.py: matrix-free PCG with the sparse H vs the dense-path InversionInterferometerSparse (use_positive_only_solver=False) built with the same MaternSparse: 9.0e-12 (coefficient 1.0) and 3.6e-11 (0.01), Witness target 1e-8; the inversion's regularization_matrix equals the sparse H exactly.
  • Worktree run: pytest test_autoarray/inversion -q → 1053 passed, 4 xfailed.

Heart YELLOW acknowledged by the human on 2026-10-21 (manifest drift 1 mismatch; release validation stale: source moved since rehearsal (PyAutoArray)).

Full API Changes (for automation & release notes)

Added

  • aa.reg.MaternSparse(coefficient, scale, nu=1.0, weights=None) — regularization_matrix_sparse_from, regularization_factor_sparse_from, regularization_matrix_from, log_det_regularization_matrix_term_from, regularization_term_from, regularization_weights_from, kernel_weights_from, mesh_shape_and_pixel_scales_from.
  • autoarray.inversion.regularization.matern_sparse.rectangular_laplacian_sparse_from(shape_native, pixel_scales).

Generated by the PyAutoLabs agent workflow.

🤖 Generated with Claude Code

Jammy2211 and others added 2 commits October 21, 2026 13:22
…rectangular meshes

nu = 1 (alpha = 2) precision H = coefficient * W^-1 c L^2 W^-1 with
L = kappa^2 I - lap (5-point, reflecting edges, per-axis pixel scales)
on the row-major rectangular mesh grid; c = e^T L^-2 e gives unit
centre variance. Sparse H and factor R for the matrix-free path, dense
H as a drop-in, exact log-det from the sparse LU of L. Non-rectangular
meshes and nu != 1 raise NotImplementedError. Phase 2 of #638 (#646).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Hand-built 4x3 L and c, SPD, log-det vs slogdet, coefficient scaling,
weights path, Delaunay and nu errors, centre variance and decay, nojax
import; PCG with the sparse Matérn H matches InversionInterferometerSparse
to 1e-8 for two coefficients (#646).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit aea99b7 into main Oct 21, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/matrix-free-interferometer-phase2 branch October 21, 2026 12:28
@Jammy2211 Jammy2211 added pending-release PR queued for the next release build and removed pending-release PR queued for the next release build labels Oct 21, 2026
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.

feat: matrix-free interferometer inversion phase 2 — sparse Matérn (SPDE) precision regularization

1 participant