Skip to content

fix: exact mesh magnification areas (RectangularUniform + adaptive rectangular) with per-mesh tests (arc phase 4a) - #664

Merged
Jammy2211 merged 6 commits into
mainfrom
feature/mesh-magnification-areas
Oct 29, 2026
Merged

Jammy2211 merged 6 commits into
mainfrom
feature/mesh-magnification-areas

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #659 — Source & Cluster arc phase 4a.

What changed

  • RectangularUniform areas_for_magnification: uses its own uniform cells centred on the overlay nodes. Before, it reused the adaptive meshes' kernel-CDF guard-ring geometry, which doesn't describe this mapper, so magnifications were off by −77% to +259%.
  • Adaptive rectangular meshes (Bilinear/RTU × Density/Image): areas_for_magnification is now the exact integral of each node's bilinear basis function, computed per axis through the mapper's own forward CDF (adaptive_rectangular_hat_areas_from). The old node-midpoint cells were wrong wherever the CDF bends across a cell. They also gave a live row zero area on coarse meshes. areas_transformed / edges_transformed (used for plotting) are unchanged.
  • New test_areas_for_magnification.py tests every mesh (all 9) for area sum, identity-lens magnification against the mapper's own integral and the analytic integral, and guard-cell behaviour.

Measured (autolens_workspace_test imaging/mesh_magnification.py, vs simulator truth)

mesh lensed before → after identity before → after
RectangularUniform +259% → −0.16% +27% → −0.48%
RectangularBilinearAdaptDensity −0.21% → −0.61% +11.23% → −0.34%
RectangularBilinearAdaptImage +14.43% → −0.57% +1.31% → −0.49%
RectangularRTUAdaptImage +8.56% → +0.08% +1.05% → +0.12%
RectangularRTUAdaptDensity −1.82% → −1.82% −0.24% → −0.26%
Delaunay / DelaunayNN −0.25% / −0.27% +0.43% / −0.41%
KNearestNeighbor / KNNBarycentric +6.10% / −1.71% −5.11% / −3.57%

KNN and KNNBarycentric still use Delaunay dual areas, which only approximate their interpolants. Their tolerances record the measured error, and the proper fix is phase 4b. RTUAdaptDensity's −1.82% lensed is unchanged by the new areas, so it comes from the reconstruction, not the areas.

Checks

  • numpy and JAX areas agree to 1e-14; jax.jit and jax.grad work and give finite gradients.
  • Quadrature convergence at 4097 samples: per-node error ~1e-6 for the kernel CDF; ~6e-4 for the rank CDF on a fully tied grid (its worst case).
  • PyAutoArray full suite: 2251 passed, 4 xfailed. PyAutoLens analysis+imaging: 191 passed. PyAutoGalaxy analysis: 64 passed.
  • Targeted workspace smoke passed: imaging/mesh_magnification.py, misc/latent/latent_integration_smoke{,_jax}.py, imaging/mesh_interpolator_source_recovery.py, misc/jax_assertions/rectangular_geometry.py. The full smoke run was cut short on 10-28 when the laptop ran low on memory, so PR CI is the first full smoke run.

Known limit

On a strongly distorted toy (radial map with a=0.3), BilinearAdaptImage's areas are +6–13% against the mapper's own integral. The areas cover the bounding box, and the separable interpolant extends into box corners that no traced data reaches. The realistic lensed check above is unaffected. This is recorded on the 4b prompt.

Companion: autolens_workspace_test PR (integration check) — merge this one first.

🤖 Generated with Claude Code

Jammy2211 and others added 5 commits October 29, 2026 20:17
…ells

The uniform mesh's geometry routed edges_transformed / areas through the
adaptive meshes' kernel-CDF guard-ring convention, which does not describe
the uniform mapper (bilinear between overlay pixel centres, no CDF, no guard
ring). Magnifications from it were biased by -77% to +259% (PyAutoArray#659).

The uniform interpolator now builds its geometry with transform="uniform",
whose edges are the uniform cells centred on every overlay node (the same
cells its imshow plot draws). xp-aware; jit/grad checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016nhQ8NkVvJhhqNSibeGcBQ
…drature)

For all nine meshes: areas sum to the analytic covered domain, the
identity-lens magnification of a reconstructed Gaussian against the mapper's
exact quadrature, and pinned guard-cell / hull-vertex / zeroed-ring
semantics. Approximate meshes carry measured, documented tolerances
(PyAutoArray#659).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016nhQ8NkVvJhhqNSibeGcBQ
…ular meshes

The adaptive rectangular meshes' areas_for_magnification pushed each node's
node-midpoint cell through the inverse CDF. That is not the integral of the
node's bilinear basis function once the CDF bends across a cell (the rank
CDF's staircase on tied coordinates, a steep adapt-image CDF), and biased
magnifications by up to +14% lensed / +11% unlensed.

New adaptive_rectangular_hat_areas_from integrates each node's separable
basis hat_r(g_y(y)) * hat_c(g_x(x)) exactly per axis, through the same
forward transform the mapper uses, over the over-sampled data's bounding
box. JAX-jit/grad safe; numpy and JAX agree to 1e-14. areas_transformed
and edges_transformed (plotting) are unchanged.

Lensed workspace check vs simulator truth: BilinearAdaptImage +14.43% ->
-0.57%, RTUAdaptImage +8.56% -> +0.08%; identity BilinearAdaptDensity
+11.23% -> -0.34%. Tolerances tightened to match.

Refs #659

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit 7fb3805 into main Oct 29, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/mesh-magnification-areas branch October 29, 2026 21:09
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.

test: mesh magnification areas — per-mesh correctness + integration check (arc phase 4a)

1 participant