Shrinkage

shrinkage::ClusteredLasso

Shrinkage for Rust · rust · 0.3.0

pub struct ClusteredLasso

Complete penalty l1 * sum_j |beta[j]| + fusion * sum_{i<j} |beta[i]-beta[j]|.

Both strengths are finite and nonnegative, checked on use. Each unordered pair contributes once. Fusion concerns signed optimization-scale values: opposite signs are distinct even when their magnitudes agree. Intercepts are unpenalized. Empty coefficient vectors are valid.

The exact prox sorts signed values, pools adjacent violations of their rank-shifted values, and soft-thresholds the pooled levels. Value and prox take O(p log p) time and reuse O(p) CPU scratch storage. There is no explicit pairwise graph. crate::ProximalGradient fits this penalty through typed and runtime composition; crate::HybridCoordinateDescent additionally performs exact Gaussian cluster-coordinate sweeps.

use shrinkage::{ClusteredLasso, Penalty, ProximalPenalty};
let penalty = ClusteredLasso::new(0.1, 0.2);
assert!((penalty.value(&[-2.0, 2.0])? - 1.2).abs() < 1e-14);
let mut output = [0.0; 2];
penalty.prox(&[-2.0, 2.0], 1.0, &mut output)?;
assert_eq!(output, [-1.7, 1.7]);

Inherent implementation

impl ClusteredLasso

fusion

pub fn fusion(&self) -> f64

Configured strength of each unordered pair difference.

l1

pub fn l1(&self) -> f64

Configured L1 strength.

new

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

Set separate L1 and uniform fusion strengths, checked on use.

Implementation of Clone

impl Clone for ClusteredLasso

clone

fn clone(&self) -> Self

Implementation of Debug

impl Debug for ClusteredLasso

fmt

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

Implementation of GapSafePenalty

impl GapSafePenalty for shrinkage::ClusteredLasso

dual_feasible

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

dual_scaling

fn dual_scaling(
    &self,
    correlations: &[f64],
    errors: &[f64]
) -> Result<Option<f64>, 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<ClusteredLasso> 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],
    _: &ClusteredLasso,
    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: &ClusteredLasso,
    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::ClusteredLasso

AtStrength

type AtStrength = ClusteredLasso;

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 ClusteredLasso

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 ClusteredLasso

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::ClusteredLasso

State

type State = State;

Implementation of Freeze

impl !Freeze for ClusteredLasso

Implementation of RefUnwindSafe

impl !RefUnwindSafe for ClusteredLasso

Implementation of Send

impl Send for ClusteredLasso

Implementation of Sync

impl !Sync for ClusteredLasso

Implementation of Unpin

impl Unpin for ClusteredLasso

Implementation of UnsafeUnpin

impl UnsafeUnpin for ClusteredLasso

Implementation of UnwindSafe

impl UnwindSafe for ClusteredLasso

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>