![](https://csdnimg.cn/release/download_crawler_static/86221019/bg1.jpg)
include ”fintrf.h” C glmnetMex.F C C Lasso and elastic-net regularized generalized linear models
C [a0,ca,ia,nin,rs q,alm,nlp,jerr] = ... C glmnetMex(parm,x,y,jd,vp,ne,nx,nlam,flmin,ulam,thr,isd,w,ka) C
[a0,ca,ia,nin,dev,alm,nlp,jerr] = ... C glmnetMex(parm,x,y,jd,vp,ne,nx,nlam,flmin,ulam,thr,isd,nc,maxit,kopt)
C C Extremely efficient procedures for fitting the entire lasso or C elastic-net regularization path for linear
regress ion, logistic and C multinomial regression models. The algorithm uses cyclical coordinate C descent
in a pathwise as described in the paper on the maintainer’s C website. C C NOTE S: This is a MEX-file
wrapper o f GLMnet.f for MATLAB. Should be called C only by glmnet.m. For details abo ut input and
output arguments, see C GLMnet.f. C C LICENSE: GPL-2 C C DATE: 13 Jul 2009 C C AUTHORS: C
Algorithm designed by Jer ome Friedman, Tre vor Hastie and Rob Tibshirani C Fortran code written by
Jerome Friedman C MATLAB wrapper written and maintained by Hui Jiang, jiangh@stanford.edu C De-
partment of Statistics, Stanford University, Stanford, California, USA. C C REFERENCES: C Friedman, J.,
Hastie, T. and Tibshirani, R. (2009) C Regular iz ation Paths for Generalized Linear Models via Coordinate
Descent. C Journal of Statistical Software, 33(1), 2010 C C EXAMPLE: C parm = 1.0; C x = [1 1; 2 2;
3 3]; C y = [1 3 2]’; C jd = 0; C vp = [1 1]’; C ne = 3; C nx = 2; C nlam = 100; C flmin = 0.0001; C
ulam = 0; C thr = 1.0e-4; C isd = 1; C w = [1 1 1]’; C ka = 2; C [a0,ca,ia,nin,rsq,a lm,nlp,jerr] = glm-
netMex(parm,x,y,jd,vp,ne,nx,nlam,flmin,ulam,thr,isd,w,ka) C C DEVELOPMENT: 13 Jul 2009: Original
version of glmnetMex.f written. C C———————————————————————–
subroutine mexFunction(nlhs, plhs, nrhs, prhs) C———————————————————————–
C (pointer) Repla c e integer by integer*8 on the DEC Alpha C 64-bit platform
mwpointer plhs(*), prhs(*) mwpointer mxCr e ateDoubleMatrix, mxGetPr mwpointer mxGetIr, mxGetJc
integer nlhs, nrhs mwsize mxGetM, mxGetN, mxGetNzmax integer mxIsNumeric integer mxIsSparse
C———————————————————————–
C Input real parm,flmin,thr,intr integer ka,no,ni,nc,ne,nx,nlam,isd,maxit,kopt,isparse,nzmax integer, di-
mension (2) :: dimx real, dimension (:), allocatable :: x,y,w,vp,ulam,cl,sr integer, dimension (:), allocatable
:: ix,jx,jd,irs,jcs
mwpointer pr
C Output integer lmu,nlp,jerr real, dimension (:), allocatable :: a0,ca,alm,dev,rsq integer, dimension (:),
allocatable :: ia,nin
C Temporary mwpointer temp
p
rmwsizetemp
m
, temp
n
, temp
n
zmaxintegertask, i
C For internal parameters real fdev, devmax, eps, big, pmin, prec integer mnlam, exmx, mxit
C Check for proper number of arguments.
if(nrhs .eq. 18 .and. nlhs .eq. 8) then task = 1; e lseif(nrhs .eq. 15 .and. nlhs .eq . 8) then task = 2;
elseif(nrhs .eq. 0) then task = 3; elseif(nrhs .eq. 9) then task = 4; else call mexErrMsgTxt(’Incorrect number
of arguments.’) endif
C Get input
if (task .eq. 3) then call get
i
nt
p
arms(f dev, eps, big, mnlam, devmax, pmin, exmx)callget
b
norm(prec, mxit)
plhs(1) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(1))callputreal(f dev, temp
p
r, 1)
plhs(2) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(2))callputreal(devmax, temp
p
r, 1)
plhs(3) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(3))callputreal(eps, temp
p
r, 1)
plhs(4) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(4))callputreal(big, temp
p
r, 1)
plhs(5) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(5))callputinteger(mnlam, temp
p
r, 1)
plhs(6) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(6))callputreal(pmin, temp
p
r, 1)
plhs(7) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(7))callputinteger(exmx, temp
p
r, 1)
plhs(8) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(8))callputreal(prec, temp
p
r, 1)
plhs(9) = mxCreateDoubleMatrix(1,1,0) temp
p
r = mxGetP r(plhs(9))callputinteger(mxit, temp
p
r, 1)elseif (task.eq.4)thentemp
mxGetP r(prhs(1))callgetreal(temp
p
r, fdev, 1)
temp
p
r = mxGetP r(prhs(2))callgetreal(temp
p
r, devmax, 1)
temp
p
r = mxGetP r(prhs(3))callgetreal(temp
p
r, eps, 1)
temp
p
r = mxGetP r(prhs(4))callgetreal(temp
p
r, big, 1)
temp
p
r = mxGetP r(prhs(5))callgetinteger(temp
p
r, mnlam, 1)
temp
p
r = mxGetP r(prhs(6))callgetreal(temp
p
r, pmin, 1)
temp
p
r = mxGetP r(prhs(7))callgetinteger(temp
p
r, exmx, 1)
temp
p
r = mxGetP r(prhs(8))callgetreal(temp
p
r, prec, 1)
1