Repository navigation
scaledLasso: the square-root lasso in one run, and CDSqrtQuadraticLoss for sufficient statistics (version 0.6.1) - #24
Merged
Merged
Conversation
The scaled lasso minimizes RSS/(2nσ) + σ/2 + λ‖β‖_ω; the minimum over σ is at σ̂ = ‖r‖/√n, which leaves the square-root lasso ‖r‖/√n + λ‖β‖_ω. scaledLasso! now solves that in one run of coordinate descent on CDSqrtLassoLoss (penalty √n λ) instead of alternating lasso fits with updates of σ̂ until σ̂ changed by less than optTol (1e-2 by default), which stopped short of the solution and solved a lasso at every iteration. Of IterLassoOptions it uses only optionsCD. CDSqrtQuadraticLoss(A, b, c), the square-root lasso loss √(x'Ax + 2b'x + c) from sufficient statistics, caches Ax and the quadratic: a coordinate update costs O(p) instead of O(n), and a coordinate that does not move O(1). The step is the exact minimizer, as for CDSqrtLassoLoss. scaledLasso!(x, f, λ, ω, options) solves the scaled lasso from it; with A = S, b = -S[:, j], c = S[j, j] and an infinite weight on j it is the regression of variable j on the others of the precision matrix estimator of Sun and Zhang (2013). Momentum and Anderson acceleration move Ax; a hook (_cacheMoved!) computes the quadratic again after a move. benchmark/scaledlasso_bench.jl compares the algorithm of 0.6.0 with the new one, from the data and from sufficient statistics. Version 0.6.1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Losses that share a checked A, as the columns of a covariance matrix in the precision matrix estimator of Sun and Zhang, paid O(p²) per loss, O(p³) for all the columns, which dominated for p ≥ 1000. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tatistics pay off Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #24 +/- ##
==========================================
- Coverage 97.88% 97.81% -0.08%
==========================================
Files 9 9
Lines 1322 1370 +48
==========================================
+ Hits 1294 1340 +46
- Misses 28 30 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
mlakolar
added a commit
that referenced
this pull request
Oct 23, 2026
ProximalOPT is now ProximalSolvers (new UUID, version 0.1.0 registering as General #173068); [deps], compat, [sources], the Julia 1.10 CI step and the code follow. Until ProximalSolvers 0.1.1 is registered, [sources] takes it from its branch sqrt-quadratic, which adds SqrtQuadraticFunction. #24 ported onto ProximalSolvers: - scaledLasso! solves the square-root lasso in one run of coordinate descent, on SqrtLeastSquaresLoss with NormL1(√n λ, ω), with options.optionsCD; σ̂ = ‖r‖/√n and the penalty is λσ̂. - CDSqrtQuadraticLoss(A, b, c; check) is the model of ProximalSolvers' SqrtQuadraticFunction, which keeps #24's exact coordinate step, the check = false path, and momentum through a hook that recomputes the value after the cache moves; scaledLasso!(x, f, λ, ω, options) on it. - #24's tests; sizes now throw DimensionMismatch, as for CDQuadraticLoss. - benchmark/scaledlasso_bench.jl and example 04 with the 0.5 names; cd_bench.jl no longer calls the removed _findInitSigma!. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes to the scaled lasso of Sun and Zhang (2012):
scaledLasso!solves the square-root lasso in one run. The scaled lasso minimizes‖r‖²/(2nσ) + σ/2 + λ ∑ ωⱼ|βⱼ|; the minimum overσis atσ̂ = ‖r‖/√n, which leaves the square-root lasso‖r‖/√n + λ ∑ ωⱼ|βⱼ|.scaledLasso!now solves that by one run of coordinate descent onCDSqrtLassoLoss(penalty√n λ). Before, it alternated lasso fits with updates ofσ̂untilσ̂changed by less thanoptTol(1e-2 by default), which stopped short of the solution and refitted a lasso at every iteration. OfIterLassoOptionsit now uses onlyoptionsCD(the other fields still drivefeasibleLasso!).CDSqrtQuadraticLoss(A, b, c; check=true), the square-root lasso loss√(x'Ax + 2b'x + c)from sufficient statistics (A = X'X/n,b = -X'y/n,c = y'y/ngives‖y - Xx‖/√n). It cachesAxand the quadratic, so a coordinate update costs O(p) instead of O(n) and a coordinate that does not move O(1); the step is the exact minimizer, with the closed form ofCDSqrtLassoLoss.scaledLasso!(x, f::CDSqrtQuadraticLoss, λ, ω, options)solves the scaled lasso from it. WithA = S,b = -S[:, j],c = S[j, j]andω[j] = Inf(an infinite weight keeps a coordinate at zero) it is the regression of variablejon the others in the precision matrix estimator of Sun and Zhang (2013);check = falseskips the O(p²) checks ofAwhen many losses share it.Momentum and Anderson acceleration move the affine cache
Ax; a hook,_cacheMoved!, computes the quadratic again after a move.Benchmarks
benchmark/scaledlasso_bench.jlon USC CARC Discovery (one CPU, AMD EPYC 7513, Julia 1.13.2; run20261023T1216Z-cd-scaledlasso; tables inbenchmark/README.md):scaledLassowas 1.2–5.4× faster than the default of 0.6.0 in 14 of 15 cases (3% slower in the last, n = 5000, p = 500, ρ = 0.9), whose coefficients were off by 2e-5 to 3e-2 (the new ones by at most 6e-6); against 0.6.0 atoptTol = 1e-6, 1.2–19× faster.Acosts O(np²) once), and slower when p ≥ n (up to 25× at p = 5000, n = 200).S: 2–90 ms for p = 200–1000, 3.4–62× faster than the newscaledLassoon copies of the data, 7–73× faster than 0.6.0's default.Against CovSel's exact homotopy (
slassoinvin CovSel #16, which follows the lasso path of each column to the scaled-lasso fixed point exactly), on its 30 speed problems (AR(1), band, Erdős–Rényi; p = 100–2000; n = p/2 and 2p; same λ₀): column by column withCDSqrtQuadraticLoss(...; check=false)took 0.9–2.1× the time ofslassoinvwith the default options, 0.6–1.6× withorder = :cyclic(faster than the homotopy for Erdős–Rényi graphs and larger p), and 1.0–2.8× atoptTol = 1e-10; the estimates agree to 1e-6 at the default tolerance and to 1e-9 atoptTol = 1e-10. Beforecheck = false, the O(p²) checks ofSin every loss made it 26–76× slower at p = 2000. So CovSel could call CoordinateDescent for this estimator at about the same speed, trading the exact solution for one within the tolerance.Behavior changes
scaledLasso!returns the solution of the jointly convex problem (to the tolerance of coordinate descent); results differ from 0.6.0 by up to the oldoptTol. The fieldsmaxIter,optTol,initProcedure,sinit,σinitofIterLassoOptionsno longer affect it, and it no longer warns about the outer iteration._findInitSigma!is removed.Relation to #23
Draft #23 (CoordinateDescent 0.7 on ProximalOPT) deletes the engine files this PR touches (
cd_differentiable_function.jl,anderson.jl,momentum.jl) and rewriteslasso.jl. Porting it means a ProximalOPT model for the square root of a quadratic (with the cached quadratic recomputed after momentum moves, as_cacheMoved!does here), andscaledLasso!on ProximalOPT's square-root least squares model.Tests
CDSqrtQuadraticLossagainstCDSqrtLassoLoss(same solution, with momentum on and off, the cyclic order with Anderson acceleration, and the path from zero), its value and gradient, infinite weights, a coordinate the loss does not depend on,check = false, input checks;scaledLassoat the optimality conditions of the lasso atλσ̂; from sufficient statistics against the data; a precision-matrix column against the regression on the other columns; argument conversion. The old outer-iteration test now checks thatmaxIter/optToldo not matter. 1181 tests pass on Julia 1.13 and 1.10;examples/04_sqrt_scaled_feasible.jlupdated and runs.🤖 Generated with Claude Code