fix(linalg): keep R^-1 row norms on their own scale in SRC - #479
Conversation
…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
📝 WalkthroughWalkthrough
ChangesScale-safe adaptive estimation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
crates/ariadnetor-linalg/src/incremental_qr.rscrates/ariadnetor-linalg/src/incremental_qr/tests.rscrates/ariadnetor-mps/src/apply/successive_randomized.rscrates/ariadnetor-mps/tests/mps/apply_successive_randomized.rs
Summary
The leave-one-out error estimate driving the adaptive stopping of successive randomized compression (SRC) was computed from squared row norms of
R^-1maintained byIncrementalQr. Those entries scale as the inverse of the sketched state's amplitude, so for anf64state 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 ofR^-1(fieldrow_inv_norms);row_normaccumulates with chainedhypot; old rows combine across appends by the Pythagorean identity (hypotof the stored norm and the new off-diagonal block's row norm); accessor renamedr_inverse_row_sq_normstor_inverse_row_norms.crates/ariadnetor-mps/src/apply/successive_randomized.rs:leave_one_out_estimateconsumes row norms, accumulating their reciprocals with the same chainedhypotand dividing bysqrt(p), wherepis the number of sketch columns absorbed so far; positivity of the row norms (guaranteed by the invertible factor) isdebug_asserted.check_append_equals_full_qrswitched to norms; newinverse_row_norms_survive_extreme_scalespins, at the incremental-QR layer, that the maintained norms scale as the inverse of the block scale;src_adaptive_is_scale_invariantgains a 1e-200 downward-scaled arm.Impact
r_inverse_row_normsis a source-breaking rename of a publicIncrementalQrmethod, 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
src_adaptive_is_scale_invariantfails 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
hypotchains; Extract a shared scale-safe accumulation primitive #478 tracks extracting a shared scale-safe accumulation primitive for the workspace.row_sq_normhelper incrates/ariadnetor-linalg/src/incremental_qr.rs; this diff renames it torow_norm.Summary by CodeRabbit
New Features
r_inverse_row_norms()API.Bug Fixes
Tests