Skip to content

feat: exact kNN mesh magnification areas (arc phase 4b) - #666

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/mesh-magnification-knn-areas
Oct 29, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/mesh-magnification-knn-areas

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #665 — Source & Cluster arc phase 4b.

What changed

  • New MeshGeometryKNearestNeighbor, built by InterpolatorKNearestNeighbor / InterpolatorKNNBarycentric. Its areas_for_magnification is the integral of each vertex's interpolation basis function over the convex hull, computed as follows:
    • evaluate the interpolator's own weights at the centres of a 256² grid (KNN_AREA_QUADRATURE_PIXELS);
    • drop the centres outside the hull;
    • sum per vertex with bincount, and rescale the total to the hull area.
  • These meshes previously borrowed the Delaunay dual areas, which are exact only for the linear Delaunay interpolant.
  • The areas are computed host-side and cached on first access, like the existing Delaunay dual-area fallback, so likelihood evaluations never pay for them (about 1–4 s when magnification is requested).

Measured

mesh unit identity μ−1 (before → after) lensed vs truth (before → after) identity vs truth
KNearestNeighbor +1.6e-2 → +1.3e-5 +6.10% → −0.23% −5.11% → −0.12%
KNNBarycentric −4.4e-2 → +1.8e-3 −1.71% → −0.40% −3.57% → −0.14%

KNNBarycentric's remaining 1.8e-3 is the coarse sub-pixel reference in the unit test; its clipped weights are discontinuous. Quadrature convergence: the identity μ moves by less than 3e-5 between 200, 400 and 800 cells per axis. Every mesh is now within 1% of simulator truth except RTUAdaptDensity lensed (−1.82%, limited by the reconstruction). DelaunayNN is the only mesh still on approximate areas (within 0.5%).

Not in this PR: #609

The partial-block neighbour-search fix was prototyped here and then split out by human ruling. It passes a brute-force oracle, but breaks the KNN + AdaptSplit gradient check in autolens_workspace_test jax_grad/knn.py. The finding and the patch are on #609. These areas integrate whatever neighbours the interpolator selects, so they're exact with or without that fix.

Checks

  • PyAutoArray full suite: 2251 passed, 4 xfailed.
  • PyAutoGalaxy full suite: 1452 passed. PyAutoLens full suite: 1015 passed, 1 xfailed.
  • Emulated no-JAX job, pixelization tests: 278 passed, 27 skipped.
  • autolens_workspace_test scripts passed: imaging/mesh_magnification.py (KNN tolerances tightened to 1%), jax_grad/knn.py, misc/jax_assertions/knn_interpolator.py, misc/jax_assertions/knn_barycentric.py, imaging/mesh_interpolator_source_recovery.py.

Companion: autolens_workspace_test PR (tolerances). Merge this one first.

🤖 Generated with Claude Code

…lant

KNearestNeighbor and KNNBarycentric used the Delaunay barycentric dual
areas, which integrate only the linear Delaunay interpolant exactly. Their
own interpolants differ, biasing magnification by up to +6.10% lensed and
-5.11% unlensed against simulator truth.

New MeshGeometryKNearestNeighbor (built by the kNN interpolators) computes
areas_for_magnification as the integral of each vertex's basis function
over the convex hull: the interpolator's own weights at the centres of a
256^2 grid, masked to the hull, summed per vertex and rescaled to the hull
area. Host-side and cached on first access, like the Delaunay fallback, so
fits never pay for it. Identity-lens error: KNN 1.6e-2 -> 1.3e-5,
KNNBarycentric 4.4e-2 -> 1.8e-3.

The partial-block neighbour bug (#609) is deliberately not fixed here; the
quadrature integrates whatever neighbours the interpolator selects.

Closes #665

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jammy2211
Jammy2211 merged commit e71feaf into main Oct 29, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/mesh-magnification-knn-areas branch October 29, 2026 22:10
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: exact KNN mesh magnification areas + fix partial-block neighbour search (arc phase 4b)

1 participant