From 65a0181221189de8f9b49f8ea62c376e96750f24 Mon Sep 17 00:00:00 2001 From: Badr-MOUFAD Date: Wed, 28 Jun 2023 11:36:20 +0200 Subject: [PATCH 1/2] fix get_next --- solvers/lasso_jl.jl | 52 ++++++++++++++++++++++----------------------- solvers/skglm.py | 3 +-- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/solvers/lasso_jl.jl b/solvers/lasso_jl.jl index 355e26c..c3f2695 100644 --- a/solvers/lasso_jl.jl +++ b/solvers/lasso_jl.jl @@ -3,48 +3,48 @@ using PyCall using SparseArrays function scipyCSC_to_julia(A) - m, n = A.shape - colPtr = Int[i + 1 for i in PyArray(A."indptr")] + m, n = A.shape + colPtr = Int[i + 1 for i in PyArray(A."indptr")] rowVal = Int[i + 1 for i in PyArray(A."indices")] nzVal = Vector{Float64}(PyArray(A."data")) - B = SparseMatrixCSC{Float64,Int}(m, n, colPtr, rowVal, nzVal) + B = SparseMatrixCSC{Float64, Int}(m, n, colPtr, rowVal, nzVal) return B end function solve_lasso( X, - y::Vector{Float64}, - lambda::Vector{Float64}, - fit_intercept::Bool, - tol::Float64, - cd_maxiter::Int, - get_null_solution::Bool, + y: : Vector{Float64}, + lambda: : Vector{Float64}, + fit_intercept: : Bool, + tol: : Float64, + cd_maxiter: : Int, + get_null_solution: : Bool, ) - p = size(X, 2) + p = size(X, 2) - w_nrow = if fit_intercept - p + 1 + w_nrow = if fit_intercept + p + 1 else - p + p end w = zeros(Float64, w_nrow, length(lambda)) if !get_null_solution - lasso_fit = fit( - LassoPath, - X, - y; - λ=lambda, - stopearly=false, - standardize=false, - intercept=fit_intercept, - maxncoef=max(size(X, 1), size(X, 2)) * 100, - cd_tol=tol, - cd_maxiter=cd_maxiter - ) - w = coef(lasso_fit) + lasso_fit = fit( + LassoPath, + X, + y + λ=lambda , + stopearly=false, + standardize=false, + intercept=fit_intercept, + maxncoef=max(size(X, 1), size(X, 2)) * 100, + cd_tol=tol, + cd_maxiter=cd_maxiter + ) + w = coef(lasso_fit) end return w diff --git a/solvers/skglm.py b/solvers/skglm.py index a76ff5a..38b0d13 100644 --- a/solvers/skglm.py +++ b/solvers/skglm.py @@ -77,8 +77,7 @@ def run(self, n_iter): intercept = self.y_offset - self.X_offset @ self.coefs self.coefs = np.vstack((self.coefs, intercept)) - @staticmethod - def get_next(previous): + def get_next(self, previous): return previous + 1 def get_result(self): From 1fdf0f6b0f82be13903816ab064eb8b7bc861b72 Mon Sep 17 00:00:00 2001 From: Badr-MOUFAD Date: Wed, 28 Jun 2023 14:23:57 +0200 Subject: [PATCH 2/2] revert unrelated changes --- solvers/lasso_jl.jl | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/solvers/lasso_jl.jl b/solvers/lasso_jl.jl index c3f2695..87954d8 100644 --- a/solvers/lasso_jl.jl +++ b/solvers/lasso_jl.jl @@ -3,49 +3,49 @@ using PyCall using SparseArrays function scipyCSC_to_julia(A) - m, n = A.shape - colPtr = Int[i + 1 for i in PyArray(A."indptr")] + m, n = A.shape + colPtr = Int[i + 1 for i in PyArray(A."indptr")] rowVal = Int[i + 1 for i in PyArray(A."indices")] nzVal = Vector{Float64}(PyArray(A."data")) - B = SparseMatrixCSC{Float64, Int}(m, n, colPtr, rowVal, nzVal) + B = SparseMatrixCSC{Float64,Int}(m, n, colPtr, rowVal, nzVal) return B end function solve_lasso( X, - y: : Vector{Float64}, - lambda: : Vector{Float64}, - fit_intercept: : Bool, - tol: : Float64, - cd_maxiter: : Int, - get_null_solution: : Bool, + y::Vector{Float64}, + lambda::Vector{Float64}, + fit_intercept::Bool, + tol::Float64, + cd_maxiter::Int, + get_null_solution::Bool, ) - p = size(X, 2) + p = size(X, 2) - w_nrow = if fit_intercept - p + 1 + w_nrow = if fit_intercept + p + 1 else - p + p end w = zeros(Float64, w_nrow, length(lambda)) if !get_null_solution - lasso_fit = fit( - LassoPath, - X, - y - λ=lambda , - stopearly=false, - standardize=false, - intercept=fit_intercept, - maxncoef=max(size(X, 1), size(X, 2)) * 100, - cd_tol=tol, - cd_maxiter=cd_maxiter - ) - w = coef(lasso_fit) + lasso_fit = fit( + LassoPath, + X, + y; + λ=lambda, + stopearly=false, + standardize=false, + intercept=fit_intercept, + maxncoef=max(size(X, 1), size(X, 2)) * 100, + cd_tol=tol, + cd_maxiter=cd_maxiter + ) + w = coef(lasso_fit) end return w -end +end \ No newline at end of file