Shrinkage

L1 (lasso)

The L1 penalty sets individual coefficients exactly to zero. Its diamond-shaped constraint region has corners on the coordinate axes, which favor sparse solutions. At zero strength, the penalty vanishes.

R(β)=λ∑j=1p∣βj∣. R(\beta) = \lambda\sum_{j=1}^p|\beta_j|.

Constraint region

Feasible region for l1 (lasso); the shaded set includes its boundary.

λ=1\lambda = 1: ∣β1∣+∣β2∣≤1|\beta_1| + |\beta_2| \leq 1. See the plot conventions for the fixed budget and coefficient scale.

Use the penalty

use shrinkage::{L1, Penalty, ProximalPenalty};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let penalty = L1::new(0.5);
    let coefficients = [2.0, -1.0];
    println!("Penalty: {}", penalty.value(&coefficients)?);
    let mut shrunk = [0.0; 2];
    penalty.prox(&coefficients, 1.0, &mut shrunk)?;
    println!("Proximal result: {shrunk:?}");
    Ok(())
}

Use coordinate descent for Gaussian lasso, IRLS for Gaussian or binomial datafits, or proximal gradient. The exact proximal map is soft-thresholding at the step size times the strength. The named Lasso model provides the Gaussian convenience API.

API: shrinkage::L1.