#source("source.R") #library(glmnet) library(lasso.path) gen_data= function (n, p, rho, snr) { rho <- min (1., max (0., rho)) x = matrix (rnorm(n), nrow=n, ncol=p, byrow=F) if (rho<1) x = matrix (rnorm(n*p), ncol=p) + sqrt(rho/(1.-rho)) * x b = ((-1)^(1:p)) * exp(-2*( (1:p)-1)/20) f = x %*% b e = rnorm(n) k = sqrt(var(f)/(snr*var(e))) y = f + k*e return (list(x=x, f=f, y=y)) } xp = function (n=100, p=2000, rho=0.1) { d <- gen_data(n, p, rho, 3) times <- numeric(3) times[1] <- unix.time ( # r1 <- glmnet (d$x, d$y, alpha=1, standardize=F, # type="naive", nlambda=min(n,p)) r1 <- lasso.path.ccd (d$x, d$y) )[1] cat (sprintf ("%20s %5.2f\n", "CCD", times[1])) times[2] <- unix.time ( r2 <- lasso.path.isolambda_descent (d$x, d$y) )[1] cat (sprintf ("%20s %5.2f\n", "isolambda-descent", times[2])) times[3] <- unix.time ( r3 <- lasso.path.homotopy (d$x, d$y) )[1] cat (sprintf ("%20s %5.2f\n", "homotopy", times[3])) return (list(times=times, data=d, glmnet=r1, lambda_descent=r2, homotopy=r3)) } res <- xp ()