Closed devmotion closed 3 years ago
Thanks for this, it looks good to me.
Maybe it would be good to always copy the weights and copy y if standardize = true - at least for me this behaviour was quite surprising and confusing.
Yes agreed this is probably not the expected behavior. Can we check if the R package takes a copy or mutates in place? There is some argument for mirroring whatever they do as closely as possible and hopefully their behavior is sensible.
Can we check if the R package takes a copy or mutates in place?
I just ran
> fit <- glmnet(x=X, y=y, weights=weights, family="gaussian")
and X
, y
, and weights
still contain the same values afterwards.
X
,y
, andweights
still contain the same values afterwards.
Great, thanks for checking that. It sounds like we should be making copies then. Feel free to either work that in here or we can merge this now and make a followup PR whenever suits, whichever you prefer
I think it would be better to address this in a separate PR, mainly because it will also require more changes and additional tests which are not related to the original purpose of this PR.
Sounds good, thanks!
Fixes the computation of the null deviation for the Gaussian family and test it with the output of the R package. Fixes https://github.com/JuliaStats/GLMNet.jl/issues/39.
The implementation is basically copied from the implementation in the R package in the file
R/elnet.R
:It has to be computed before the
ccall
since the call modifies the weights in-place and additionallyy
ifstandardize = true
. Maybe it would be good to alwayscopy
the weights andcopy
y
ifstandardize = true
- at least for me this behaviour was quite surprising and confusing.Additionally, I changed the types in the
ccall
s according to the Julia documentation:The vectors of fixed length 1 in the
ccall
are replaced withRef
.