Shrinkage

shrinkage::ChainFusedLasso

Shrinkage for Rust · rust · 0.3.0

pub struct ChainFusedLasso

Complete penalty l1 * sum_j |beta[j]| + fusion * sum_j w[j] * |beta[j+1]-beta[j]|.

Edges follow feature order and contribute once. Both strengths and every weight must be finite and nonnegative, checked on use. Unit weights are implicit unless Self::with_weights supplies exactly one weight per edge. Zero weights cut the chain. Empty and single-feature chains have no edges. Intercepts are excluded, and coefficients refer to the optimization scale.

The exact complete prox uses weighted taut strings followed by uniform L1 soft-thresholding. Value and prox take O(p) time; the prox reuses O(p) CPU storage. crate::ProximalGradient supports typed and runtime problems, and crate::HybridCoordinateDescent adds exact Gaussian segment-coordinate sweeps.

use shrinkage::{ChainFusedLasso, Penalty, ProximalPenalty};
let penalty = ChainFusedLasso::new(0.1, 0.2).with_weights(vec![2.0, 0.0]);
assert!((penalty.value(&[-2.0, 2.0, 1.0])? - 2.1).abs() < 1e-14);
let mut output = [0.0; 3];
penalty.prox(&[-2.0, 2.0, 1.0], 1.0, &mut output)?;
assert_eq!(output, [-1.5, 1.5, 0.9]);

Inherent implementation

impl ChainFusedLasso

fusion

pub fn fusion(&self) -> f64

Configured multiplier of the edge weights.

l1

pub fn l1(&self) -> f64

Configured L1 strength.

new

pub fn new(l1: f64, fusion: f64) -> Self

Set independent L1 and fusion strengths, with implicit unit weights.

weights

pub fn weights(&self) -> Option<&[f64]>

Explicit edge weights, or None for implicit unit weights.

with_weights

pub fn with_weights(self, weights: Vec<f64>) -> Self

Supply one finite, nonnegative weight per adjacent edge, checked on use.

Implementation of Clone

impl Clone for ChainFusedLasso

clone

fn clone(&self) -> Self

Implementation of Debug

impl Debug for ChainFusedLasso

fmt

fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result

Implementation of GapSafePenalty

impl GapSafePenalty for shrinkage::ChainFusedLasso

dual_feasible

fn dual_feasible(
    &self,
    correlations: &[f64],
    errors: &[f64]
) -> Result<bool, FitError>

has_sparsity

fn has_sparsity(&self) -> bool

prox_zeroed

fn prox_zeroed(
    &self,
    input: &[f64],
    zeroed: &[bool],
    step: f64,
    output: &mut [f64]
) -> Result<(), FitError>

screen_zeros

fn screen_zeros(
    &self,
    correlations: &[f64],
    errors: &[f64],
    zeroed: &mut [bool]
) -> Result<(), FitError>

Implementation of Partition

impl Partition<ChainFusedLasso> for State

labels

fn labels(&self) -> &[usize]

new

fn new(n: usize, p: usize) -> Self

rebuild

fn rebuild<M: RawColumns<f64> + lazymatrix::MatrixErrorType>(
    &mut self,
    matrix: &LazyMatrix<M>,
    coefficients: &[f64],
    residual: &[f64],
    penalty: &ChainFusedLasso,
    iteration: usize
) -> Result<(), FitError<<M as >::Error>>

set_screened

fn set_screened(&mut self, zeroed: &[bool])

set_weights

fn set_weights(&mut self, weights: &[f64])

sweep_observed

fn sweep_observed<E, T: SolverObserver + ?Sized>(
    &mut self,
    coefficients: &mut [f64],
    intercept: &mut f64,
    fit_intercept: bool,
    penalty: &ChainFusedLasso,
    iteration: usize,
    observer: &mut T
) -> Result<(), FitError<E>>

sweep_visits

fn sweep_visits(&self) -> (usize, usize)

values

fn values(&self) -> Vec<f64>

Implementation of PathPenalty

impl PathPenalty for shrinkage::ChainFusedLasso

AtStrength

type AtStrength = ChainFusedLasso;

at_strength

fn at_strength(&self, lambda: f64) -> Result<Self, FitError>

maximum_penalty

fn maximum_penalty(&self, gradient: &[f64]) -> Result<PenaltyMaximum, FitError>

Implementation of Penalty

impl Penalty for ChainFusedLasso

Error

type Error = FitError;

validate_input

fn validate_input(&self, coefficients: &[f64]) -> Result<(), FitError>

value

fn value(&self, coefficients: &[f64]) -> Result<f64, FitError>

Implementation of ProximalPenalty

impl ProximalPenalty for ChainFusedLasso

gap_safe

fn gap_safe(&self) -> Option<&dyn shrinkage::GapSafePenalty>

prox

fn prox(
    &self,
    input: &[f64],
    step: f64,
    output: &mut [f64]
) -> Result<(), FitError>

Implementation of ReducedCoordinatePenalty

impl ReducedCoordinatePenalty for shrinkage::ChainFusedLasso

State

type State = State;

Implementation of Freeze

impl !Freeze for ChainFusedLasso

Implementation of RefUnwindSafe

impl !RefUnwindSafe for ChainFusedLasso

Implementation of Send

impl Send for ChainFusedLasso

Implementation of Sync

impl !Sync for ChainFusedLasso

Implementation of Unpin

impl Unpin for ChainFusedLasso

Implementation of UnsafeUnpin

impl UnsafeUnpin for ChainFusedLasso

Implementation of UnwindSafe

impl UnwindSafe for ChainFusedLasso

Implementation of Any

impl<T> Any for T where T: 'static + ?Sized

Implementation of Borrow

impl<T> Borrow<T> for T where T: ?Sized

Implementation of BorrowMut

impl<T> BorrowMut<T> for T where T: ?Sized

Implementation of ByRef

impl<T> ByRef<T> for T

Implementation of CastableFrom

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?Sized

Implementation of CastableFrom

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?Sized

Implementation of CloneToUninit

impl<T> CloneToUninit for T where T: Clone

Implementation of From

impl<T> From<T> for T

Implementation of Imply

impl<T, U> Imply<T> for U where T: ?Sized, U: ?Sized

Implementation of Into

impl<T, U> Into<U> for T where U: From<T>

Implementation of IntoEither

impl<T> IntoEither for T

Implementation of Pointable

impl<T> Pointable for T

Implementation of Read

impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?Sized

Implementation of Same

impl<T> Same for T

Implementation of SupersetOf

impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>

Implementation of ToOwned

impl<T> ToOwned for T where T: Clone

Implementation of TryFrom

impl<T, U> TryFrom<U> for T where U: Into<T>

Implementation of TryInto

impl<T, U> TryInto<U> for T where U: TryFrom<T>