make_lambda_path

Function make_lambda_path 

Source
pub fn make_lambda_path(
    x: &Matrix,
    y: &[f64],
    options: &LambdaPathOptions,
    penalty_factor: Option<&[f64]>,
    intercept_col: Option<usize>,
) -> Vec<f64>
Expand description

Generates a lambda path from lambda_max down to lambda_min.

This creates a logarithmically-spaced sequence of lambda values, matching glmnet’s approach for regularization paths.

§Arguments

  • x - Standardized design matrix (n × p)
  • y - Centered response vector (n elements)
  • options - Lambda path generation options
  • penalty_factor - Optional per-feature penalty factors
  • intercept_col - Index of intercept column (typically 0)

§Returns

A vector of lambda values in decreasing order (largest to smallest).

§Lambda Sequence

The lambda values are logarithmically spaced:

lambda[k] = lambda_max * exp(log(lambda_min_ratio) * k / (nlambda - 1))

For ridge (alpha ≈ 0), we use a small alpha value to compute a finite lambda_max, then use that lambda sequence for the actual ridge fit.

§Default lambda_min_ratio

Following glmnet:

  • If n >= p: lambda_min_ratio = 0.0001
  • If n < p: lambda_min_ratio = 0.01