libqe 0.2.5
QE C++ library
Loading...
Searching...
No Matches
lasso.hpp File Reference

Coordinate-descent Lasso for multivariate response with k-fold CV. More...

#include <armadillo>
#include <cmath>
#include <limits>
#include <stdexcept>

Go to the source code of this file.

Namespaces

namespace  qe
 

Functions

double qe::soft_threshold (double z, double gamma) noexcept
 Soft-threshold (shrinkage) operator used by coordinate descent.
 
arma::vec qe::lasso_cd (const arma::mat &X, const arma::vec &y, double lambda, const arma::vec &pf, arma::vec beta0={}, int max_iter=1000, double tol=1e-7)
 Single-response Lasso via cyclic coordinate descent at a fixed lambda.
 
double qe::lasso_lambda_max (const arma::mat &X, const arma::mat &Yc, const arma::vec &pf)
 Compute the smallest lambda that drives all penalized coefficients to zero.
 
arma::mat qe::lasso_x1_contribution (const arma::mat &X_raw, const arma::mat &Y, const arma::uvec &x1_cols, const arma::vec &pf, int n_lambda=50, int k_folds=5, double eps=0.01)
 Cross-validated multivariate Lasso; returns fitted values for target columns only.
 

Detailed Description

Coordinate-descent Lasso for multivariate response with k-fold CV.

Mirrors glmnet(x, y, family = "mgaussian", penalty.factor = ...) with k-fold cross-validation to select lambda, and warm-starts along the lambda path for efficiency.

The public entry point is qe::lasso_x1_contribution(), which returns an n×q matrix of fitted values attributable to the "target" predictors at the CV-selected lambda. It is used by generalized_means_rotation to isolate the target variable's contribution to the ENA point space after controlling for covariates.

**Penalty factors (pf):**

  • 0.0 — predictor is always included (forced in; no shrinkage)
  • 1.0 — standard L1 penalty

The caller is responsible for building the model matrix (main effects and/or interactions); this function accepts a numeric matrix, not a formula.