| Title: | Faster and more Efficient Lasso (than 'glmnet' and 'scalreg') with Data-Driven Tuning |
|---|---|
| Description: | Fits Lasso paths for high-dimensional regression using coordinate descent with automatic, data-driven tuning of the regularization parameter. The implementation is 10 to 50 times faster than the standard 'glmnet' implementation of Lasso and over 100 times faster than scaled Lasso. It also provides a reliable estimate of the regression noise level. |
| Authors: | Tathagata Sadhukhan [aut, cre], Ines Wilms [aut], Stephan Smeekes [aut], Sumanta Basu [aut] |
| Maintainer: | Tathagata Sadhukhan <[email protected]> |
| License: | GPL (>=2) |
| Version: | 0.1.0 |
| Built: | 2026-09-21 09:45:52 UTC |
| Source: | https://github.com/tathagata-s/autotune |
This package fits lasso path for high-dimensional regression using coordinate descent while automatically tuning it's regularization parameter. autotune Lasso is 10-50 times than the standard glmnet implementation of lasso, and over 100 times faster than scaled lasso. Additionally, it gives reliable noise level estimate for the regression problem.
| Package: | autotune |
| Type: | Package |
| Version: | 1.0 |
| Date: | 2025-09-18 |
Very simple to use. Accepts x,y data for linear regression model,
and produces the regularization path which automatically estimates an
optimal tuning parameter lambda.
Only 1 function, more autotune algorithms for VAR, random forests, coming soon!
Tathagata Sadhukhan Ines Wilms Stephan Smeekes
and Sumanta Basu
Maintainer: Tathagata Sadhukhan([email protected])
set.seed(10) n <- 80 p <- 500 s <- 5 type <- 1 snr <- 3 betatrue <- c(rep(1,s), rep(0, p - s)) x <- scale(matrix(rnorm(n * p), ncol = p)) error.sd <- sqrt((betatrue %*% betatrue)/snr) err <- rnorm(n, sd = error.sd) y <- x %*% betatrue + err y <- y - mean(y) ans <- autotune_lasso(x, y, trace_it = TRUE) b <- betatrue # The Predictors which are actually significant: which(b != 0) # The Predictors which had nonzero estmated coefficients: which(ans$beta != 0) # Top 10 predictors X_i's in the ranking of X_i's given by autotune: ans$sorted_predictors[1:10] + 1 # No of significant predictors in each CD iteration when sigma_hat is allowed to vary: ans$count_sig_beta # Sigma estimates in each CD iteration: ans$sigma2_seq # Empirical noise variance: var(err)set.seed(10) n <- 80 p <- 500 s <- 5 type <- 1 snr <- 3 betatrue <- c(rep(1,s), rep(0, p - s)) x <- scale(matrix(rnorm(n * p), ncol = p)) error.sd <- sqrt((betatrue %*% betatrue)/snr) err <- rnorm(n, sd = error.sd) y <- x %*% betatrue + err y <- y - mean(y) ans <- autotune_lasso(x, y, trace_it = TRUE) b <- betatrue # The Predictors which are actually significant: which(b != 0) # The Predictors which had nonzero estmated coefficients: which(ans$beta != 0) # Top 10 predictors X_i's in the ranking of X_i's given by autotune: ans$sorted_predictors[1:10] + 1 # No of significant predictors in each CD iteration when sigma_hat is allowed to vary: ans$count_sig_beta # Sigma estimates in each CD iteration: ans$sigma2_seq # Empirical noise variance: var(err)
Fits a linear model via alternative optimization of penalized gaussian maximum likelihood
which is a biconvex function of regression coefficients and noise variance .
The regularization path of autotune_lasso quickly picks out a good lambda for Lasso and then
returns the corresponding linear fit along with various attributes related to the fit.
autotune_lasso( x, y, alpha = 0.01, standardize = TRUE, standardize_response = TRUE, intercept = TRUE, active = FALSE, trace_it = FALSE, tolerance = 1e-04, beta_tolerance = 0.001, iter_max = 30, beta_iter_max = 40, active_iter_max = 5, PR_norm_l2 = FALSE, ... )autotune_lasso( x, y, alpha = 0.01, standardize = TRUE, standardize_response = TRUE, intercept = TRUE, active = FALSE, trace_it = FALSE, tolerance = 1e-04, beta_tolerance = 0.001, iter_max = 30, beta_iter_max = 40, active_iter_max = 5, PR_norm_l2 = FALSE, ... )
x |
Matrix of predictors, with one column for each predictor.
Dimension will be |
y |
Vector of responses. |
alpha |
Default 0.01, significance level of sequential F-tests used for estimation of support set. |
standardize |
Logical flag for standardization of all variables in x, prior to
fitting the model sequence. The coefficients are always returned on the
original scale. Default value is |
standardize_response |
Logical flag for demeaning the reponse variable y.
Default value is |
intercept |
Should intercept(s) be fitted (default= |
active |
Should active set selection be used ( |
trace_it |
Logical input, default |
tolerance |
Numeric input for an additional stopping criteria on the
coordinate descent when sigma is updating. Stops that coordinate
descent when the relative change between successive iterates of
coefficients' estimates is less than the |
beta_tolerance |
Numeric input for the stopping criteria on the
coordinate descent when sigma is not updating. Stops that coordinate
descent when the relative change between successive iterates of
coefficients' estimates is less than the |
iter_max |
Maximum number of iterations of coordinate descent allowed when sigma is updating. Default value is 30. |
beta_iter_max |
Maximum number of iterations of coordinate descent allowed when sigma is not updating. Default value is 40. |
active_iter_max |
If |
PR_norm_l2 |
Logical flag to whether use the l2 norm of partial residuals for ordering them instead of the default l1 norm. |
... |
Additional arguments passed to the internal fitting routine. |
A list with various intermediate and final outputs produced by autotune Lasso in its regularization path.
beta |
Final estimates of regression coefficients. |
a0 |
Intercept of the fit. |
lambda |
Final thresholding value |
sigma_sq |
Final estimate of noise variance |
nobs |
Number of observations. |
nvars |
Number of variables. |
CD.path.details |
A list of additional details about the coordinate descent path taken by autotune Lasso:
|
library(autotune) set.seed(10) n <- 80 p <- 400 s <- 5 snr <- 4 betatrue <- c(rep(1,s), rep(0, p - s)) x <- matrix(rnorm(n * p), ncol = p) error.sd <- sqrt((betatrue %*% betatrue)/snr) err <- rnorm(n, sd = error.sd) y <- x %*% betatrue + err ans <- autotune_lasso(x, y, trace_it = TRUE) b <- betatrue # The Predictors which are actually significant: which(b != 0) # The Predictors which had nonzero estmated coefficients: which(ans$beta != 0) # Top 10 predictors X_i's in the ranking of X_i's given by autotune: ans$CD.path.details$sorted_predictors[1:10] # Cardinality of autotune's estimated support set in each CD iteration before lambda converged: ans$CD.path.details$count_sig_beta # Sigma estimates in each CD iteration: ans$CD.path.details$sigma_sq_seq # Empirical noise variance: var(err)library(autotune) set.seed(10) n <- 80 p <- 400 s <- 5 snr <- 4 betatrue <- c(rep(1,s), rep(0, p - s)) x <- matrix(rnorm(n * p), ncol = p) error.sd <- sqrt((betatrue %*% betatrue)/snr) err <- rnorm(n, sd = error.sd) y <- x %*% betatrue + err ans <- autotune_lasso(x, y, trace_it = TRUE) b <- betatrue # The Predictors which are actually significant: which(b != 0) # The Predictors which had nonzero estmated coefficients: which(ans$beta != 0) # Top 10 predictors X_i's in the ranking of X_i's given by autotune: ans$CD.path.details$sorted_predictors[1:10] # Cardinality of autotune's estimated support set in each CD iteration before lambda converged: ans$CD.path.details$count_sig_beta # Sigma estimates in each CD iteration: ans$CD.path.details$sigma_sq_seq # Empirical noise variance: var(err)
This function extracts the regression coefficients estimated by an autotune
lasso model, using the stored "autotune_lasso" object
## S3 method for class 'autotune_lasso' coef(object, intercept = TRUE, path = FALSE, sparse = TRUE, ...) ## S3 method for class 'autotune_lasso_path' coef(object, intercept = TRUE, a0 = NULL, ...)## S3 method for class 'autotune_lasso' coef(object, intercept = TRUE, path = FALSE, sparse = TRUE, ...) ## S3 method for class 'autotune_lasso_path' coef(object, intercept = TRUE, a0 = NULL, ...)
object |
An |
intercept |
Logical; include the intercept term? If |
path |
Logical; if |
sparse |
Logical; controls the output format of |
... |
Other arguments to coef. |
a0 |
Intercept of the fitted autotune regression. Used only when |
coef.autotune_lasso(path = FALSE, sparse = TRUE) returns a sparse dgCMatrix
of dimension (nvars + 1) (or nvars if intercept = FALSE).
coef.autotune_lasso(path = FALSE, sparse = FALSE) returns a named numeric vector.
coef.autotune_lasso(path = TRUE) calls coef.autotune_lasso_path(), which returns a sparse
dgCMatrix of dimension (nvars + 1) (k + 1) (or nvars (k + 1) if
intercept = FALSE), with columns named lambda_1, ..., lambda_k, final_lambda.
set.seed(10) n = 300 p = 500 s = 10 beta = c(rep(1, s), rep(0, p - s)) x = matrix(rnorm(n * p), ncol = p) # Maunal sigma allocation # y = x %*% beta + rnorm(n, sd = 1) # Dynamic sigma allocation with snr specified snr = 2 y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr)) fit <- autotune_lasso(x, y) coef(fit) # final solution coef(fit, path = TRUE) # coefficient path (sparse)set.seed(10) n = 300 p = 500 s = 10 beta = c(rep(1, s), rep(0, p - s)) x = matrix(rnorm(n * p), ncol = p) # Maunal sigma allocation # y = x %*% beta + rnorm(n, sd = 1) # Dynamic sigma allocation with snr specified snr = 2 y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr)) fit <- autotune_lasso(x, y) coef(fit) # final solution coef(fit, path = TRUE) # coefficient path (sparse)
Plots for autotune_lasso objects
## S3 method for class 'autotune_lasso' plot(x, max_preds = NULL, cumulative = TRUE, ...)## S3 method for class 'autotune_lasso' plot(x, max_preds = NULL, cumulative = TRUE, ...)
x |
Fitted |
max_preds |
Integer input stating maximum number of predictors to include in the plot.
Default NULL (then max_preds is calculated internally). Plotting R-squared
involves running |
cumulative |
Logical input. If TRUE, plots cumulative R-squared; if FALSE, plots adjusted R-squared. |
... |
Other graphical parameters to plot |
Returns a data frame with columns:
r_squared: Cumulative R-squared values
adj_r_squared: Adjusted R-squared values
has_nonzero_beta: logical vector whose element
indicates whether the ranked predictor has a
non-zero coefficient or not.
# Fit autotune lasso set.seed(10) n = 300 p = 500 s = 10 beta = c(rep(1, s), rep(0, p - s)) x = matrix(rnorm(n * p), ncol = p) # Maunal sigma allocation # y = x %*% beta + rnorm(n, sd = 1) # Dynamic sigma allocation with snr specified snr = 2 y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr)) fit <- autotune_lasso(x, y) # Basic diagnostic plot plot(fit) # Plot adjusted R-squared for first 15 predictors plot(fit, max_preds = 15, cumulative = FALSE)# Fit autotune lasso set.seed(10) n = 300 p = 500 s = 10 beta = c(rep(1, s), rep(0, p - s)) x = matrix(rnorm(n * p), ncol = p) # Maunal sigma allocation # y = x %*% beta + rnorm(n, sd = 1) # Dynamic sigma allocation with snr specified snr = 2 y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr)) fit <- autotune_lasso(x, y) # Basic diagnostic plot plot(fit) # Plot adjusted R-squared for first 15 predictors plot(fit, max_preds = 15, cumulative = FALSE)
Predict from a autotune_lasso fit
## S3 method for class 'autotune_lasso' predict( object, newx = NULL, type = c("response", "coefficients"), path = NULL, ... )## S3 method for class 'autotune_lasso' predict( object, newx = NULL, type = c("response", "coefficients"), path = NULL, ... )
object |
An object of class |
newx |
Numeric matrix of new |
type |
Character; one of |
path |
For |
... |
Further arguments passed from the generic. |
If type = "response", returns the prediction at the x provided for prediction.
If type = "coefficients", returns the fitted coefficients.
set.seed(10) n = 300 p = 500 s = 10 beta = c(rep(1, s), rep(0, p - s)) x = matrix(rnorm(n * p), ncol = p) # Maunal sigma allocation # y = x %*% beta + rnorm(n, sd = 1) # Dynamic sigma allocation with snr specified snr = 2 y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr)) fit <- autotune_lasso(x, y) predict(fit, newx = x[1:5, , drop = FALSE]) predict(fit, type = "coefficients") predict(fit, type = "coefficients", path = TRUE)set.seed(10) n = 300 p = 500 s = 10 beta = c(rep(1, s), rep(0, p - s)) x = matrix(rnorm(n * p), ncol = p) # Maunal sigma allocation # y = x %*% beta + rnorm(n, sd = 1) # Dynamic sigma allocation with snr specified snr = 2 y = x %*% beta + rnorm(n, sd = sqrt(var(x%*%beta)/snr)) fit <- autotune_lasso(x, y) predict(fit, newx = x[1:5, , drop = FALSE]) predict(fit, type = "coefficients") predict(fit, type = "coefficients", path = TRUE)
The sp500 data file contains a year's worth of close-of-day data
for most of the Standard and Poor's 500 stocks. The data are in reverse
chronological order, with the first row corresponding to December 31,
2008.
data("sp500")data("sp500")
A list containing the following two matrices:
sp500.percentA 252 by 494 matrix of daily percentage changes. The first column is the DJIA index, the second is the S&P 500 index, and the remaining columns are labeled individual stocks.
sp500.2008A 253 by 494 matrix of raw close-of-day data. The first column is the DJIA index, the second is the S&P 500 index, and the remaining columns are labeled individual stocks.
Redistributed from version 1.0.1 of the GPL-2-licensed R package scalreg.
This database was used in the R package plus.
data("sp500") names(sp500) dim(sp500$sp500.percent) attach(sp500) head(sp500.percent[, 1:5]) detach(sp500)data("sp500") names(sp500) dim(sp500$sp500.percent) attach(sp500) head(sp500.percent[, 1:5]) detach(sp500)