Skip to content

lachioma/glmnet_matlab

Repository files navigation

glmnet_matlab_R2020

Glmnet Logo

Glmnet compiled for MATLAB R2020b, Windows 10 64-bit.

Update: Glmnet compiled for R2020b seems to work fine on R2021a and R2022b.

N.B. Check Releases and Branches for different MATLAB versions (e.g. R2020a).

I also fixed cvglmnet.m, updating the old functions for parallel computing (from matlabpool to parpool).

Installation

The code from this repository is plug-and-play: just download the folder, add it to your MATLAB path and run your GLM!

Background

Glmnet is an extremely efficient package for fitting the entire lasso or elastic-net path for linear regression, logistic and multinomial regression, Poisson regression and the Cox model. It is way faster than MATLAB lassoglm that comes with the Statistics and Machine Learning Toolbox.

Glmnet provided by the authors are not compatible with newer versions of MATLAB (>R2016, I read somewhere). Indeed, my Matlab 2020a on Windows 10 was going into fatal crash when running the original code. Also the code provided by growlix did not work on my system. So I compiled again the Fortran code which glmnet is based on (and makes it so fast). Glmnet does work fine now on my system (MATLAB R2020a, Windows 10 64-bit).

Implementation

N.B. The glmnet toolbox that comes with this repository is already compiled, i.e. the code is plug-and-play: just download the release for a specific MATLAB version, add the code folder to your MATLAB path and run your GLM!
You do not have to run the following steps - these are just to compile glmnet from scracth.

To compile the glmnet code, I first installed:

Then, in MATLAB, I moved into the glmnet folder and ran

mex -v COMPFLAGS='$COMPFLAGS /real_size:64 /integer_size:64' glmnetMex.F GLMnet.f

Please cite the authors if you use Glmnet:

Glmnet for Matlab (2013) Qian, J., Hastie, T., Friedman, J., Tibshirani, R. and Simon, N.
http://www.stanford.edu/~hastie/glmnet_matlab/

Sources