Skip to content

fix(linalg): keep R^-1 row norms on their own scale in SRC - #479

Merged
ultimatile merged 1 commit into
mainfrom
fix/476-loo-estimate-scale
Jul 16, 2026
Merged

fix(linalg): keep R^-1 row norms on their own scale in SRC#479
ultimatile merged 1 commit into
mainfrom
fix/476-loo-estimate-scale

Conversation

@ultimatile

@ultimatile ultimatile commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

The leave-one-out error estimate driving the adaptive stopping of successive randomized compression (SRC) was computed from squared row norms of R^-1 maintained by IncrementalQr. Those entries scale as the inverse of the sketched state's amplitude, so for an f64 state scaled below roughly 1e-154 the squares overflow to infinity, the reciprocals collapse to zero, and the estimate is exactly zero — the sweep accepts the initial sketch size with no signal. This PR maintains row norms instead and keeps every accumulation on the values' own scale. Closes #476.

Changes

  • crates/ariadnetor-linalg/src/incremental_qr.rs: maintain row norms of R^-1 (field row_inv_norms); row_norm accumulates with chained hypot; old rows combine across appends by the Pythagorean identity (hypot of the stored norm and the new off-diagonal block's row norm); accessor renamed r_inverse_row_sq_norms to r_inverse_row_norms.
  • crates/ariadnetor-mps/src/apply/successive_randomized.rs: leave_one_out_estimate consumes row norms, accumulating their reciprocals with the same chained hypot and dividing by sqrt(p), where p is the number of sketch columns absorbed so far; positivity of the row norms (guaranteed by the invertible factor) is debug_asserted.
  • Tests: accessor migration and the from-scratch reference in check_append_equals_full_qr switched to norms; new inverse_row_norms_survive_extreme_scales pins, at the incremental-QR layer, that the maintained norms scale as the inverse of the block scale; src_adaptive_is_scale_invariant gains a 1e-200 downward-scaled arm.

Impact

r_inverse_row_norms is a source-breaking rename of a public IncrementalQr method, and the returned quantity changes from squared norms to norms. The only consumers are the SRC estimator and the incremental-QR unit tests, both migrated here.

Test plan

  • The new 1e-200 arm of src_adaptive_is_scale_invariant fails before this change (the selected bond collapses from 3 to 1) and passes after.
  • inverse_row_norms_survive_extreme_scales: a two-append history scaled by 1e-200 reports finite row norms equal to 1e200 times the unscaled run's, exercising both the first-block and the old-row update paths.
  • cargo make gate (fmt-check, clippy with denied warnings, workspace tests and doctests) passes.

Notes

Summary by CodeRabbit

  • New Features

    • Added access to inverse row norms through the renamed r_inverse_row_norms() API.
  • Bug Fixes

    • Improved numerical stability when tracking inverse row norms, including under extremely large or small scaling factors.
    • Updated adaptive error estimation to use row norms without unnecessary squaring, reducing overflow risk.
    • Preserved inverse tracking reliably across append failures and rank-deficient terminations.
  • Tests

    • Expanded coverage for extreme-scale inputs and scale-invariant adaptive behavior.

…mate

The incremental QR maintained squared row norms of R^-1, whose
entries scale as the inverse of the sketched state's amplitude: for an
f64 state scaled below ~1e-154 the squares overflow to infinity, the
leave-one-out estimate collapses to exactly zero, and the adaptive
sweep spuriously converges at the initial sketch size.

Maintain row norms instead, accumulated with chained hypot (per-element
in row_norm, Pythagorean combine across appends), and accumulate the
estimator's reciprocal sum the same way so neither the norms nor their
reciprocals are ever squared. Rename r_inverse_row_sq_norms to
r_inverse_row_norms; all workspace consumers migrated.

Extend src_adaptive_is_scale_invariant with a 1e-200 downward-scaled
case and pin the scale covariance of the maintained norms at the
incremental-QR layer.

Closes #476
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

IncrementalQr now tracks Euclidean inverse row norms with overflow-resistant accumulation. The adaptive estimator consumes these norms using hypot, and tests cover extreme positive and negative scaling.

Changes

Scale-safe adaptive estimation

Layer / File(s) Summary
Incremental QR row-norm tracking
crates/ariadnetor-linalg/src/incremental_qr.rs, crates/ariadnetor-linalg/src/incremental_qr/tests.rs
Inverse tracking, its public accessor, append updates, and tests now use Euclidean row norms accumulated with hypot.
Adaptive estimator integration
crates/ariadnetor-mps/src/apply/successive_randomized.rs, crates/ariadnetor-mps/tests/mps/apply_successive_randomized.rs
Leave-one-out estimation consumes inverse row norms, and scale-invariance tests cover both 1e200 and 1e-200.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

I’m a rabbit with norms in my burrow tonight,
hypot keeps the numbers both steady and bright.
Squared overflow hops out of sight,
While scales high and low now test right.
Adaptive ranks bounce along—what a delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main linalg change: keeping R^-1 row norms on their own scale for SRC.
Linked Issues check ✅ Passed The PR addresses #476 by switching to row norms, using scale-safe accumulation, and adding the requested extreme-scale tests.
Out of Scope Changes check ✅ Passed The changes stay focused on the incremental-QR and SRC estimator fixes, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/476-loo-estimate-scale

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/ariadnetor-linalg/src/incremental_qr/tests.rs`:
- Around line 210-215: Update the expected-norm calculation in the test around
g_full to accumulate values with T::Real::hypot instead of summing squared
magnitudes and taking sqrt, matching the production implementation’s safe norm
accumulation while preserving the same result.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 81b42987-409f-4a71-95ef-d6d47a395c18

📥 Commits

Reviewing files that changed from the base of the PR and between e660b70 and 2e434d0.

📒 Files selected for processing (4)
  • crates/ariadnetor-linalg/src/incremental_qr.rs
  • crates/ariadnetor-linalg/src/incremental_qr/tests.rs
  • crates/ariadnetor-mps/src/apply/successive_randomized.rs
  • crates/ariadnetor-mps/tests/mps/apply_successive_randomized.rs

Comment thread crates/ariadnetor-linalg/src/incremental_qr/tests.rs
@ultimatile
ultimatile merged commit ada44ec into main Jul 16, 2026
1 check passed
@ultimatile
ultimatile deleted the fix/476-loo-estimate-scale branch July 17, 2026 05:27
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.

Leave-one-out estimate collapses to zero for extreme state scales

1 participant