diff --git a/src/lar.jl b/src/lar.jl index 03a2efe..27288ee 100644 --- a/src/lar.jl +++ b/src/lar.jl @@ -289,9 +289,9 @@ function lars(X::Matrix{T}, y::Vector{T}; method::Symbol=:lasso, # The system is becoming too ill-conditioned. # We have degenerate vectors in our active set. # We'll 'drop for good' the last regressor added - warn(@sprintf "Regressors in active set degenerate. Dropping a regressor, after %i iterations, i.e. λ=%.3e, with an active set of %i regressors, and the smallest cholesky pivot element being %.3e" niter lambda nactive diag) + @warn(@sprintf "Regressors in active set degenerate. Dropping a regressor, after %i iterations, i.e. λ=%.3e, with an active set of %i regressors, and the smallest cholesky pivot element being %.3e" niter lambda nactive diag) # XXX: need to figure a 'drop for good' way - unshift!(Cov, removed_Cov) + pushfirst!(Cov, removed_Cov) Cov[1] = Cov[C_idx] Cov[C_idx] = 0 continue @@ -312,7 +312,7 @@ function lars(X::Matrix{T}, y::Vector{T}; method::Symbol=:lasso, # bringing in too much numerical error that is greater than # than the remaining correlation with the # regressors. Time to bail out - warn(@sprintf "Early stopping the lars path, as the residues are small and the current value of lambda is no longer well controlled. %i iterations, λ=%.3e, previous λ=%.3e, with an active set of %i regressors." niter lambda prev_lambda nactive) + @warn(@sprintf "Early stopping the lars path, as the residues are small and the current value of lambda is no longer well controlled. %i iterations, λ=%.3e, previous λ=%.3e, with an active set of %i regressors." niter lambda prev_lambda nactive) break end diff --git a/test/runtests.jl b/test/runtests.jl index 6a883d8..7288e93 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ using LARS, Test, DelimitedFiles, Statistics, LinearAlgebra +using StableRNGs # Diabetes data set from Efron, Hastie, Johnstone, and Tibshirani (2004) diabeetus = readdlm(joinpath(dirname(@__FILE__), "diabeetus.csv"), ',', header=true)[1] @@ -102,3 +103,15 @@ coefs = [ c = lars(X, y, method=:lar, standardize=false, intercept=false) @test c.lambdas ≈ lambdas @test c.coefs ≈ coefs + +@testset "degenerate regressors produces warning" begin + + rng = StableRNG(123) + n = 100 + p = 5 + X = randn(rng, n, p) + X[:, 2] = X[:, 1] + 1e-10*randn(n) + y = X[:, 1] + randn(n) + @test_logs (:warn, r"^Regressors in active set degenerate.") lars(X, y, method=:lars) + +end