Registry Mirror
Skip to content

Conversation

@mtantaoui

Copy link
Copy Markdown
Contributor

Elastic net: compute only the diagonal of the inverse for the variances

Every fit computes the variance of the parameters, which needs only the diagonal of
(XᵀX)⁻¹. It was computing the full inverse with QR, about 700 ms for 512
features, often more than the solver itself.

Changes

  • XᵀX = L Lᵀ (Cholesky), so (XᵀX)⁻¹ = L⁻ᵀ L⁻¹ and entry j is the squared norm
    of column j of L⁻¹. L⁻¹ is built a row at a time, on contiguous rows, using
    only its lower triangle. Matches the QR result to about 1e-14 relative (new test).
  • The blas path (invh_into) is unchanged, except that it now keeps only the
    diagonal.

Behavior change

With exactly collinear features (e.g. a duplicated column), XᵀX is singular.
Before, the QR inverse returned Ok with NaN z-scores for those features; now
Cholesky fails and z_score() / confidence_95th() return
Err(ElasticNetError::IllConditioned) (new test).

Results

Fits on independent features, where the solver needs only a few passes and the
variance dominates: f64, n = 5 000, penalty 0.1. Core Ultra 7 155H, one core.

features master this PR speedup with #469 with #469 + this PR speedup
128 31.5 ms 27.0 ms 1.2× 12.4 ms 6.8 ms 1.8×
256 134.2 ms 74.5 ms 1.8× 84.5 ms 23.1 ms 3.7×
512 1118.8 ms 464.4 ms 2.4× 757.7 ms 100.4 ms 7.5×

Measured with the criterion bench from #469 plus a group on independent features.
With both PRs, a 512-feature fit goes from 1119 ms to 100 ms (11×).

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.02%. Comparing base (935c437) to head (87dfd43).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #470      +/-   ##
==========================================
+ Coverage   76.95%   77.02%   +0.07%     
==========================================
  Files         105      105              
  Lines        7612     7631      +19     
==========================================
+ Hits         5858     5878      +20     
+ Misses       1754     1753       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant