shrinkage::Lasso
Shrinkage for Rust · rust · 0.3.0
Source: src/model/lasso.rs
Gaussian lasso configuration.
Fits ||y - X_tilde * beta - beta_0||² / (2n) + lambda * ||beta||₁. The intercept is unpenalized. By default, X_tilde uses training-column means and population standard deviations, and the penalty acts on the normalized coefficients. Reported coefficients and predictions use the original input scale.
Dense and CSC matrices use the same statically dispatched iteration routine. Solver storage is O(n + p); neither a normalized matrix nor a Gram matrix is materialized. Options are validated when Self::fit is called.
use Mat;
use ;
let x = from_fn;
let fit = new.fit?;
assert_eq!;
let predictions = fit.predict?;
Inherent implementation
Source: src/model/lasso.rs
cross_validate_path
Source: src/model/lasso.rs
Cross-validate explicit lambda candidates in caller preference order.
Each fold reuses coordinate-descent storage across its entire path. The result retains fold paths and a fresh full-data path after selection.
Errors
Reject invalid folds, empty candidates, supplied preprocessing vectors, and failed or nonconverged fits, with fold context when available.
cross_validate_regularization_path
Source: src/model/lasso.rs
Cross-validate automatic paths using training-fold anchors and preprocessing.
Paths share relative strengths, and every fold fits the entire sequence. The selected fraction is refitted with the full-data anchor and preprocessing.
Errors
Reject invalid options or folds, supplied preprocessing vectors, and any failed or nonconverged fit. Errors identify the fold when available.
fit
Source: src/model/lasso.rs
Fit against raw training columns and a response slice.
Zero-feature designs are supported. Zero-norm normalized columns stay at zero. The fitted result owns its parameters and does not borrow x.
Errors
Returns LassoError::InvalidInput for invalid dimensions, empty observations, nonfinite inputs, or invalid options. A preprocessing failure retains its backend source in LassoError::Backend. Finite inputs whose arithmetic produces nonfinite values return LassoError::NumericalFailure. Iteration limits return a fit instead.
fit_intercept
Source: src/model/lasso.rs
Enable or disable the unpenalized intercept.
With Normalization::Auto, disabling the intercept also disables centering while retaining population-standard-deviation scaling. Explicit normalization choices are honored independently. Explicit centering can induce a fixed original-scale intercept even when this option is disabled.
fit_path
Source: src/model/lasso.rs
Fit explicit strengths in caller order with warm starts and reused storage. The builder's single-fit lambda is replaced by these values. Defaults resolve the stopping criterion separately for each point.
Errors
Returns validation or fitting errors without a partial path.
fit_regularization_path
Source: src/model/lasso.rs
Generate and fit a decreasing regularization path with one preparation.
Errors
Returns invalid sequence options, input failures, or numerical errors.
lambda_max
Source: src/model/lasso.rs
Calculate the smallest lambda with optimal zero optimization coefficients. Uses the builder's intercept and normalization settings.
Errors
Returns validation, preprocessing, or arithmetic failures.
max_iterations
Source: src/model/lasso.rs
Set a strictly positive limit on coordinate sweeps over the current working set.
An initially optimal fit takes zero sweeps. Reaching the limit returns a finite fit with Termination::IterationLimit, not convergence.
new
Source: src/model/lasso.rs
Configure a fit with a finite, nonnegative penalty strength.
Defaults to an intercept, Normalization::Auto, a relative duality gap tolerance of 1e-6, and at most 10_000 coordinate sweeps over the current working set. At zero penalty, the default is absolute KKT tolerance 1e-6: scaling a residual cannot generally construct a useful zero-penalty dual vector.
normalize
Source: src/model/lasso.rs
Select a training-column normalization preset or custom specification.
Defaults to Normalization::Auto. Use Normalization::None for the raw design or Normalization::Custom to choose centering and scaling independently. Computed zero scales are replaced with one. Penalties act on normalized coefficients; reported parameters and predictions use the original scale.
terminate_on
Source: src/model/lasso.rs
Select the stopping criterion and its tolerances.
The duality gap uses a fixed reference loss from the zero-coefficient model, with the intercept optimized when enabled. The legacy Self::tolerance setter selects absolute KKT violation.
tolerance
Source: src/model/lasso.rs
Set a finite, strictly positive absolute KKT tolerance.
With c_j = X_tilde_j' * residual / n, the violation is |c_j - lambda * sign(beta_j)| for nonzero coefficients and max(|c_j| - lambda, 0) otherwise. When fitting an intercept, include |mean(residual)|. Convergence requires the largest violation to be at most this tolerance, confirmed after reconstructing the residual.
with_centers
Source: src/model/lasso.rs
Supply column centers instead of computing them from the training data.
This overrides the centering rule selected by Self::normalize. Each center must be finite, and the vector must have one entry per column. The values are checked by Self::fit. If scales are computed using L1, L2, or maximum-absolute scaling, they use these centers.
with_scales
Source: src/model/lasso.rs
Supply column scales instead of computing them from the training data.
This overrides the scaling rule selected by Self::normalize. Each scale must be finite and strictly positive, and the vector must have one entry per column. The values are checked by Self::fit.
working_set_policy
Source: src/model/lasso.rs
Select the working-set policy for single fits and paths.
working_sets
Source: src/model/lasso.rs
Enable automatic working sets, or disable heuristic restrictions. The last working-set setter wins.
Implementation of Clone
Source: src/model/lasso.rs
clone
Source: src/model/lasso.rs
Implementation of Debug
Source: src/model/lasso.rs
fmt
Source: src/model/lasso.rs
Implementation of Freeze
Implementation of RefUnwindSafe
Implementation of Send
Implementation of Sync
Implementation of Unpin
Implementation of UnsafeUnpin
Implementation of UnwindSafe
Implementation of Any
Implementation of Borrow
Implementation of BorrowMut
Implementation of ByRef
Implementation of CastableFrom
Implementation of CastableFrom
Implementation of CloneToUninit
Implementation of From
Implementation of Imply
Implementation of Into
Implementation of IntoEither
Implementation of Pointable
Implementation of Read
Implementation of Same
Implementation of SupersetOf
Implementation of ToOwned
Implementation of TryFrom
Implementation of TryInto
