diff --git a/src/CoxNet.jl b/src/CoxNet.jl index 7e121c5..93188b5 100644 --- a/src/CoxNet.jl +++ b/src/CoxNet.jl @@ -91,7 +91,7 @@ function glmnet!(X::Matrix{Float64}, y::Matrix{Float64}, family::CoxPH; constraints::Array{Float64, 2}=[x for x in (-Inf, Inf), y in 1:size(X, 2)], dfmax::Int=size(X, 2)+1, pmax::Int=min(dfmax*2+20, size(X, 2)), nlambda::Int=100, - lambda_min_ratio::Real=(length(y) < size(X, 2) ? 1e-2 : 1e-4), + lambda_min_ratio::Real=(size(y, 1) < size(X, 2) ? 1e-2 : 1e-4), lambda::Vector{Float64}=Float64[], tol::Real=1e-7, standardize::Bool=true, intercept::Bool=true, maxit::Int=1000000) @validate_and_init diff --git a/src/GLMNet.jl b/src/GLMNet.jl index 2fafcd7..cd21242 100644 --- a/src/GLMNet.jl +++ b/src/GLMNet.jl @@ -342,7 +342,7 @@ function glmnet!(X::Matrix{Float64}, y::Matrix{Float64}, penalty_factor::Vector{Float64}=ones(size(X, 2)), constraints::Array{Float64, 2}=[x for x in (-Inf, Inf), y in 1:size(X, 2)], dfmax::Int=size(X, 2), pmax::Int=min(dfmax*2+20, size(X, 2)), nlambda::Int=100, - lambda_min_ratio::Real=(length(y) < size(X, 2) ? 1e-2 : 1e-4), + lambda_min_ratio::Real=(size(y, 1) < size(X, 2) ? 1e-2 : 1e-4), lambda::Vector{Float64}=Float64[], tol::Real=1e-7, standardize::Bool=true, intercept::Bool=true, maxit::Int=1000000, algorithm::Symbol=:newtonraphson) @validate_and_init @@ -385,7 +385,7 @@ function glmnet!(X::SparseMatrixCSC{Float64,Int32}, y::Matrix{Float64}, penalty_factor::Vector{Float64}=ones(size(X, 2)), constraints::Array{Float64, 2}=[x for x in (-Inf, Inf), y in 1:size(X, 2)], dfmax::Int=size(X, 2), pmax::Int=min(dfmax*2+20, size(X, 2)), nlambda::Int=100, - lambda_min_ratio::Real=(length(y) < size(X, 2) ? 1e-2 : 1e-4), + lambda_min_ratio::Real=(size(y, 1) < size(X, 2) ? 1e-2 : 1e-4), lambda::Vector{Float64}=Float64[], tol::Real=1e-7, standardize::Bool=true, intercept::Bool=true, maxit::Int=1000000, algorithm::Symbol=:newtonraphson) @validate_and_init diff --git a/src/Multinomial.jl b/src/Multinomial.jl index 5d9b5e5..2126788 100644 --- a/src/Multinomial.jl +++ b/src/Multinomial.jl @@ -144,7 +144,7 @@ function glmnet!(X::Matrix{Float64}, y::Matrix{Float64}, penalty_factor::Vector{Float64}=ones(size(X, 2)), constraints::Array{Float64, 2}=[a for a in (-Inf, Inf), y in 1:size(X, 2)], dfmax::Int=size(X, 2)+1, pmax::Int=min(dfmax*2+20, size(X, 2)), nlambda::Int=100, - lambda_min_ratio::Real=(length(y) < size(X, 2) ? 1e-2 : 1e-4), + lambda_min_ratio::Real=(size(y, 1) < size(X, 2) ? 1e-2 : 1e-4), lambda::Vector{Float64}=Float64[], tol::Real=1e-7, standardize::Bool=true, intercept::Bool=true, maxit::Int=1000000, grouped_multinomial::Bool=false, algorithm::Symbol=:newtonraphson) diff --git a/test/runtests.jl b/test/runtests.jl index 4b56ac8..25b34f2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -189,6 +189,12 @@ cv4 = glmnetcv(X, y; rng=MersenneTwister(1)) # Test previously ambiguous definitions glmnet(float.(X), y) glmnetcv(float.(X), y) + +# Check for issue #72 +nobs = size(X, 2) - 1 +glmnetcv(X[1:nobs, :], y[1:nobs], nfolds=2) +nobs = size(X, 2) + 1 +glmnetcv(X[1:nobs, :], y[1:nobs], nfolds=2) end @@ -355,6 +361,12 @@ cv = glmnetcv(X, yl, Binomial(); folds=[1,1,1,1,2,2,2,3,3,3]) show(IOBuffer(), cv) show(IOBuffer(), cv.path) +# Check for issue #72 +nobs = size(X, 2) - 1 +glmnetcv(X[1:nobs, :], yl[1:nobs, :], Binomial(), nfolds=2) +nobs = size(X, 2) + 1 +glmnetcv(X[1:nobs, :], yl[1:nobs, :], Binomial(), nfolds=2) + # Passing RNG makes cv deterministic cv1 = glmnetcv(X, yl, Binomial()) cv2 = glmnetcv(X, yl, Binomial()) @@ -532,6 +544,12 @@ cv = glmnetcv(X, y, Poisson(); folds=[1,1,1,1,2,2,2,3,3,3]) show(IOBuffer(), cv) show(IOBuffer(), cv.path) +# Check for issue #72 +nobs = size(X, 2) - 1 +glmnetcv(X[1:nobs, :], y[1:nobs], Poisson(), nfolds=2) +nobs = size(X, 2) + 1 +glmnetcv(X[1:nobs, :], y[1:nobs], Poisson(), nfolds=2) + # Passing RNG makes cv deterministic cv1 = glmnetcv(X, y, Poisson()) cv2 = glmnetcv(X, y, Poisson()) @@ -602,6 +620,12 @@ coxcv = glmnetcv(dat[:,3:size(dat,2)], dat[:,1], dat[:,2], lambda = cox_lambda, show(IOBuffer(), coxcv) show(IOBuffer(), coxcv.path) +# Check for issue #72 +X = dat[:,3:size(dat,2)] +nobs = size(X, 2) - 1 +glmnetcv(X[1:nobs, :], dat[1:nobs,1], dat[1:nobs,2], nfolds=2) +nobs = size(X, 2) + 1 +glmnetcv(X[1:nobs, :], dat[1:nobs,1], dat[1:nobs,2], nfolds=2) # Passing RNG makes cv deterministic cv1 = glmnetcv(dat[:,3:size(dat,2)], dat[:,1], dat[:,2]) @@ -670,6 +694,13 @@ iris_cv2 = glmnetcv(iris_x, iris_yy, Multinomial(), folds = multi_folds) # Make sure show works show(IOBuffer(), iris_cv) show(IOBuffer(), iris_cv.path) + +# Check for issue #72 +X = [iris_x iris_x] +nobs = size(X, 2) - 1 +glmnetcv(X[1:nobs, :], iris_yy[1:nobs, :], Multinomial(), nfolds=2) +nobs = size(X, 2) + 1 +glmnetcv(X[1:nobs, :], iris_yy[1:nobs, :], Multinomial(), nfolds=2) end @testset "MvNormal" begin @@ -725,4 +756,10 @@ end @test path.lambda ≈ R_lambda @test path.a0 ≈ R_a0 -end \ No newline at end of file + # Check for issue #72 + nobs = size(X, 2) - 1 + glmnetcv(X[1:nobs, :], Y[1:nobs, :], MvNormal()) + nobs = size(X, 2) + 1 + glmnetcv(X[1:nobs, :], Y[1:nobs, :], MvNormal()) + +end