Repository navigation
feat: MaternSparse sparse Matérn (SPDE) precision regularization (phase 2 of #638) - #650
Merged
Merged
Conversation
…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>
This was referenced Oct 21, 2026
This was referenced Oct 26, 2026
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.
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 raiseNotImplementedError. Mesh pixel ordering verified row-major from the top-left onRectangularUniformand the adapt-density mesh. DenseMaternKerneluntouched. No priors config (fit wiring is phase 5).API Changes
Additive only:
aa.reg.MaternSparseandregularization.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 vsnp.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-pathInversionInterferometerSparse(use_positive_only_solver=False) built with the sameMaternSparse: 9.0e-12 (coefficient 1.0) and 3.6e-11 (0.01), Witness target 1e-8; the inversion'sregularization_matrixequals the sparse H exactly.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