Repository navigation
feat: exact kNN mesh magnification areas (arc phase 4b) - #666
Merged
Merged
Conversation
…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>
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 #665 — Source & Cluster arc phase 4b.
What changed
MeshGeometryKNearestNeighbor, built byInterpolatorKNearestNeighbor/InterpolatorKNNBarycentric. Itsareas_for_magnificationis the integral of each vertex's interpolation basis function over the convex hull, computed as follows:KNN_AREA_QUADRATURE_PIXELS);bincount, and rescale the total to the hull area.Measured
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
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