Skip to content

Fix per-point speed in adaptive curvature weighting - #259

Merged
den-sq merged 3 commits into
mainfrom
fix/258-adaptive-curvature-speed
Nov 20, 2026
Merged

den-sq merged 3 commits into
mainfrom
fix/258-adaptive-curvature-speed

Conversation

@den-sq

@den-sq den-sq commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adaptive slicing used a single norm for the entire derivative batch in both curvature calculations. This changes the normalized curvature contribution from the intended |r' × r''| / |r'|² to |r' × r''|, making slice placement depend incorrectly on parameter speed. Both norms now operate per point.

Closes #258.

  • Add analytical regressions using a radius-two circle with angle t + t²: constant curvature across speeds and batch sizes, correct curvature contributions, and uniform physical progress through the public adaptive sampler.
  • Preserve the adaptive-output compatibility text below for the v1.6.2 GitHub Release body, the established location for release notes. Equidistant slicing is unchanged.
  • Recalibrate only the existing tube fixture's binary centroid-distance bound from 0.10 to 0.15 voxels. Corrected geometry changes the measured value from 0.071276 to 0.118912; every other existing accuracy bound still passes. Fixture inputs, reconstruction algorithms, metrics, and all other bounds are unchanged.

Compatibility note for the v1.6.2 release body

Include this text when preparing the v1.6.2 GitHub Release body; no v1.6.2 release draft exists yet:

Fixed adaptive slicing's curvature weighting to use the spline speed at each point instead of one norm for the whole curve (#258). Adaptive slice positions, and therefore straightened output, can change for the same trace and options compared with earlier versions. Equidistant slicing is unchanged.

Validation

  • 249 passed across spline helpers, pipeline tests, and round-trip metric tests.
  • 26 passed with warnings treated as errors across spline helpers, the tube round-trip regression, and round-trip metrics.
  • The original implementation fails all three new tests. Fixing only the curvature denominator still fails the cumulative-weighting and public-sampler tests; fixing only the contribution speed fails all three. The corrected sampler's maximum angular-progress error is 0.000127 radians against the 0.001-radian quadrature allowance.
  • git diff --check passes. The review follow-up only removes the README note; release/README.md is byte-for-byte identical to main, and no release/** changes remain in the PR. Python tests were not rerun for this documentation-only follow-up.

Validated the actual 77-point PSD trace from octo9_p7_psd_trace_ouroboros.json through the production parser and sampler (trace SHA-256: e53d873f1c44472f0002558335130ddead9a3d3fd280443a66866ec2d98d0fe3). Its dense arc length is 5365.361 voxels. At one-voxel spacing, both versions produce 5362 slices:

Adaptive ratio Median Euclidean slice-position displacement Maximum displacement
0.5 (default) 3.014 voxels 15.053 voxels
1.0 4.243 voxels 26.105 voxels

Corrected cumulative curvature matches an independent per-row calculation. Parameters remain finite and nondecreasing with endpoints 0 and 1. Ratio-zero and equidistant parameters and positions are bitwise identical before and after. These measurements confirm the expected placement change; they are not an accuracy-improvement claim.

Shared-basis audit

Inspected the existing Spline.calculate_adaptive_parameters, calculate_spline_curvature, calculate_curvature_parameterization, adaptive_curvature_parameterization, calculate_arc_length, and SlicesGeometryPipelineStep path.

  • Per-point curvature: calculate_spline_curvature remains the sole production calculation of curvature. The global Frobenius-norm denominator is removed and replaced with each derivative row's speed cubed.
  • Cumulative curvature weighting: calculate_curvature_parameterization continues to consume that curvature and owns its speed weighting and cumulative sum. Its scalar batch-speed path is removed. No persistent speed state, parallel curvature helper, or alternate production formula is introduced.
  • Adaptive placement: the existing normalization, ratio blending, inverse mapping, arc-length estimate, sample-count convention, and pipeline consumer are retained. There are no new serialized carriers or boundary conversions that could become another authority.
  • Load-bearing decisions: retain the current cumulative-sum quadrature and supported-input behavior, including zero-speed handling; this issue corrects the two norms without changing integration or degeneracy policy. The analytical circle establishes the mathematical expectation before the explicitly reported geometry-dependent fixture recalibration.
  • Release-note ownership: inspected the documentation's GitHub Releases link, publish-release.yml, and release/artifact-inputs.json. The GitHub Release body is the published release-note source; the release README describes mechanics and is also an artifact input. Removed the unconsumed Unreleased notes section instead of adding a new release-preparation step. The compatibility text above is a handoff for the v1.6.2 body, not a second repository changelog. No workflow, artifact-input definition, or version changes are introduced.

@tavateva tavateva left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Hold the merge until CI has actually run, though. All three workflows on 60d6855 (PR Test Coverage, Build and Certify Server Image, Build Release Artifacts) are at action_required and waiting for maintainer approval, so nothing has executed on this head yet.

The fix: both np.linalg.norm(first_derivative) calls now use axis=1. The integrand becomes κ·|r'| = |r'×r''|/|r'|² per sample, which is exactly what #258 describes. calculate_arc_length already used per-point norms, and no other caller of the two functions is affected.

Tests: the analytic circle (radius 2, angle t + t²) is the regression #258 asked for, and each of the three tests checks a distinct property: curvature is independent of speed and batch, each sample's contribution equals its turning rate, and the public sampler's progress is uniform in arc length.

  • I put main's spline.py under the new tests: all 3 fail, and the 12 existing spline tests still pass.
  • At the PR head with -W error, spline + round-trip regression + metrics gave 26 passed. test/helpers + test/pipeline + metrics gave 616 passed. The one warning there is starlette's httpx deprecation from test_options, which comes from my environment, not this change. flake8 is clean.

Fixture recalibration: I re-measured the tube fixture at this head. The binary centroid distance is 0.118912, matching the PR body, so the bound moving from 0.10 to 0.15 is a geometry change, not a looser tolerance. Every other measurement still clears its bound comfortably. The nearest is the weighted centroid at 0.061 against 0.08, and the binary per-slice maximum actually improved, from 0.536 to 0.505.

PSD trace: the displacement figures (median/max 3.0/15.0 voxels at ratio 0.5, 4.2/26.1 at ratio 1.0) agree with the independent measurement in #258.

Non-blocking:

  • Release note location: release/README.md documents the release mechanics, while release notes are published in the GitHub Release body. No release step reads an "Unreleased notes" section, so it relies on someone moving it at release time. It's also under release/**, an artifact input, which is why this Python-only fix triggers the release-artifacts workflow. Minimum response: drop the section and add the compatibility line to the v1.6.2 release body when you write it. Keeping it is fine too, as long as release prep moves it into the body and clears it.

@den-sq
den-sq merged commit b40ccb0 into main Nov 20, 2026
14 checks passed
@den-sq
den-sq deleted the fix/258-adaptive-curvature-speed branch November 20, 2026 23:43
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.

Adaptive slicing: curvature term uses a global derivative norm instead of per-point speed

2 participants