Skip to content

fix: Sibson weights from the cavity boundary, regular at internal edges - #685

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/sibson-internal-edge-continuity
Nov 9, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/sibson-internal-edge-continuity

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #610. This implements the approved plan (plan comment). Tier judge; merge by human /prm. PR 1 of 2 (split by repo); the workspace PR is documentation-only, see below.

Summary

Bug. The Watson per-triangle decomposition formed a circle through the query q and every edge of every cavity triangle, including cavity-interior edges whose terms cancel in exact arithmetic. On an internal edge that circle is collinear:

  • On an internal edge, the code fell back to the seed triangle's barycentric row. That's only right on hull edges; the square centre got 0.5 / 0.5 on the diagonal instead of 0.25 × 4.
  • Near an internal edge, the huge cancelling terms were normalised before negatives were clipped, giving Σw = 1.1239 at 1e-8 and jumps up to 0.0268 across edges.

Fix: natural-neighbour areas from the cavity boundary. Each neighbour's stolen area |cell_new(q) ∩ cell_old(v)| is a sum of per-edge segment terms ½·cross(P−q, P′−q):

  • Cavity-interior edges use only stored circumcentres.
  • The circle through q is formed only on cavity-boundary edges.
  • The q|v bisector is split at (q+v)/2, which keeps every term local to one edge: static-shape for JAX, a flat loop for numba.
  • Clockwise triangles negate their terms (qhull doesn't guarantee CCW).

So internal edges are never singular.

Rules by case:

  • On a vertex, or outside the hull: unchanged.
  • Exact collinearity with a hull edge: linear rule on that edge.
  • Everything else, including exactly on internal edges: the boundary formulation.
  • Round-off-sized areas (≤ 1e-12·total) are snapped to 0 before normalising, so all bodies select the same support. A negative area beyond −1e-10·total marks the row degenerate (the perf: skip Sibson row padding in adaptive signals and unique mappings (DelaunayNN imaging) #629 contract is kept).
  • Selected entries are compacted to the front of each row, so there are no -1 holes.

The same algorithm is in _sibson_single_from_tables (NumPy/JAX) and _sibson_numba._sibson_from_tables (parallel + serial builds).

⚠️ Likelihood values change (maintainer-set tier judge)

DelaunayNN likelihoods change wherever data points sit on or near internal edges. That's common: traced image-mesh vertices are data-pixel centres, and regular meshes are exactly cocircular. No currently pinned autolens_workspace_test likelihood uses DelaunayNN (51/51 scripts pass, below).

Also in this PR: DelaunayNN magnification areas

imaging/mesh_magnification.py's DelaunayNN identity leg went from −0.41% to −2.65% (1% tolerance), because its areas were the Delaunay dual areas, an approximation the old interpolant happened to flatter. I proved the interpolant itself correct on exact lattices (≤ 5e-12 vs the oracle). DelaunayNN now integrates its own Sibson basis functions, the kNN quadrature from #665, now shared via basis_quadrature_points_from / basis_integral_areas_from: identity +0.04%, lensed −0.23%, better than main's −0.41% / −0.27%. This affects only areas_for_magnification (the magnification diagnostic and plotting), not the likelihood. kNN behaviour is unchanged.

Performance (numba, HST size: 61,600 queries, 1,530 vertices, 4 cores, interleaved with main)

build main this PR
serial (every Nautilus worker) 50.7 / 51.6 ms 39.4 / 41.1 ms (about 20% faster)
parallel (prange), medians 16.4 / 14.2 ms 12.6 / 12.4 ms (min 9.6–11.5 vs 11.7–12.0)

A first port was 1.5–2.8× slower. Three exact rewrites removed that:

  • Cavity membership uses the walk's own circumcircle predicate instead of an O(C²) scan.
  • Edge credits are pre-summed per triangle vertex (3C insertions).
  • Totals run in one pass over the live entries.

The dead _pairwise_sum / _block_sum helpers are removed. The open Mind draft sibson_serial_kernel_loses_allocation_hoisting should be re-measured on this body.

API Changes

Internal algorithm change. Sibson weights at and near internal edges change (correct now); DelaunayNN likelihoods and magnification areas change.
See full details below.

Test Plan

  • New test_sibson_internal_edges.py (43 tests, numpy / numba / jax-jit) against an independent Voronoi half-plane-clipping oracle (test-local, no production code):
    • Square centre gives 0.25 × 4 for both diagonal choices and both windings (hand-built tables, including clockwise triangles); regular hexagon centre gives 1/6 × 6.
    • Asymmetric fixtures (random mesh, 2:1 rectangle, kite) match the oracle to < 1e-10.
    • Both-sided internal-edge probes at ±1e-2 / ±1e-6 / ±1e-8 / ±1e-12 / nextafter on a lattice and a random mesh: |w(±δ) − w(0)| ≤ 200·δ + 1e-12.
    • Affine precision 1e-11, partition 1e-12, w ≥ 0, support ⊆ natural neighbours.
    • Hull edges: linear on the edge, O(d) convergence from inside; the outside fallback is unchanged.
    • NumPy = numba = JAX-jit: exact integers, weights 1e-12.
    • Numba tolerances equal the reference module's.
    • DelaunayNN basis areas: interior lattice areas equal h² (symmetry), tile the hull, and integrate linear fields.
  • Discrimination: with the source reverted, 28 of the 41 algorithm tests fail. The 13 that pass on main cover the hull rule, outside fallback and parity, which were already right.
  • Audit strict xfails promoted (3): test_sibson_square_center_matches_independent_symmetry_oracle, test_sibson_near_edge_preserves_partition_after_positive_filter, and test_exact_nextafter_boundary_continuity_and_locator_fault[sibson].
  • test_sibson_numba.py::test__thin_triangle__…: it pinned the old symptom (NaN rows 1e-15 off an internal edge). It's rewritten to pin the correct behaviour: finite partition, continuous across the edge, off-edge neighbours kept; values checked against the oracle (≤ 1.3e-12).
  • Full suite: 2402 passed, 1 skipped, 0 xfailed.
  • autolens_workspace_test (on the fix: oversampled fine state when the blurring mask is padded #358 branch, whose pins include fix: pseudo-determinant for intrinsic regularization log det H #683): the full smoke list, every imaging and interferometer jax_likelihood script, misc/jax_assertions/{delaunay_nn, delaunay_nn_caps}.py and imaging/jax_grad/delaunay.py: 51/51 pass. That includes imaging/mesh_magnification.py and mesh_interpolator_source_recovery.py.
Full API Changes (for automation & release notes)

Added

  • autoarray.inversion.mesh.interpolator.sibson.sibson_mappings_weights_from(points_np, query_points_np, …): NumPy Sibson rows for arbitrary query points.
  • autoarray.inversion.mesh.interpolator.sibson.SIBSON_ZERO_AREA_TOLERANCE, SIBSON_NEGATIVE_AREA_TOLERANCE.
  • autoarray.inversion.mesh.mesh_geometry.delaunay.MeshGeometryDelaunayNN, basis_quadrature_points_from, basis_integral_areas_from.

Removed

  • _sibson_numba._pairwise_sum, _block_sum (private, now unused).

Changed Behaviour

  • Sibson weights (InterpolatorDelaunayNN, mesh.DelaunayNN) on and near internal Delaunay edges: correct natural-neighbour weights, continuous across edges. Hull edges use the linear rule only on exact collinearity.
  • InterpolatorDelaunayNN.mesh_geometry.areas_for_magnification: Sibson basis integrals instead of the Delaunay dual areas.
  • Rows that were NaN-degenerate near internal edges are now regular.

Migration

  • None in code. Stored DelaunayNN likelihoods and evidences from before this fix are not comparable to new ones.

Generated by the PyAutoLabs agent workflow.


Generated by Claude Code

…ges (#610)

The Watson per-triangle decomposition formed a circle through the query and
every edge of every cavity triangle, including cavity-interior edges whose
terms cancel. On an internal edge that circle is collinear: the code fell back
to the seed triangle's barycentric row (correct only on hull edges; square
centre got 0.5/0.5 on the diagonal instead of 0.25 x 4), and near one the huge
cancelling terms were normalised before negatives were clipped (sum 1.12).

Natural-neighbour areas are now summed from per-edge segment terms of the
stolen regions (stored circumcentres on cavity-interior edges; the circle
through q only on cavity-BOUNDARY edges; q|v bisector split at (q+v)/2), with
a clockwise triangle negating its terms. Internal edges are never singular.
Linear hull-edge rule only on exact hull collinearity. Round-off-sized areas
snapped to 0 before normalising; clearly negative ones mark the row degenerate.
Selected entries compacted to the front of each row.

Same algorithm in the NumPy/JAX body and the numba body (parallel + serial).
Numba serial kernel ~20% faster than before at HST size (61,600 queries).

DelaunayNN magnification areas now integrate the Sibson basis (the kNN
quadrature, shared): the dual-area approximation biased the identity-lens
magnification by -2.65% once internal-edge weights were corrected; +0.04% now.

Validation: independent Voronoi-clipping oracle (<=1e-10), square centre both
diagonals and windings, hexagon 1/6, both-sided finite/nextafter edge probes
(Lipschitz), affine/partition/support, hull limit, NumPy/numba/JAX-jit parity.
Audit strict xfails (3) promoted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016nhQ8MFwfRFgwBVbYjP9Xd
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Nov 9, 2026 — with Claude
@Jammy2211
Jammy2211 merged commit af80e69 into main Nov 9, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/sibson-internal-edge-continuity branch November 9, 2026 14:11
@pyautolabs-bot pyautolabs-bot Bot removed the pending-release PR queued for the next release build label Nov 12, 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.

fix: Preserve Sibson coordinates across internal edges

2 participants