Shrinkage

shrinkage::Slope

Shrinkage for Rust · rust · 0.3.0

pub struct Slope

SLOPE penalty sum_j weights[j] * |beta|_(j) on optimization coefficients.

|beta|_(j) denotes the jth largest coefficient magnitude. Supply one finite, nonnegative, nonincreasing weight per coefficient, including the penalty strength. Equal weights give L1; all zero weights give no penalty. An empty weight vector defines the penalty on an empty coefficient vector. Intercepts are excluded by the fitting APIs.

The exact proximal map sorts magnitudes, projects the thresholded values onto nonincreasing, nonnegative sequences by pooling adjacent violations, and restores the original signs and order. Sorting costs O(p log p) and pooling costs O(p). Owned CPU scratch storage is reused across calls. Typed Gaussian problems also support crate::HybridCoordinateDescent, combining full PG transitions with exact signed magnitude-cluster sweeps.

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

let penalty = Slope::new(vec![3.0, 1.0]);
assert_eq!(penalty.value(&[-3.0, 3.0])?, 12.0);
let mut output = [0.0; 2];
penalty.prox(&[-3.0, 3.0], 1.0, &mut output)?;
assert_eq!(output, [-1.0, 1.0]);

Inherent implementation

impl Slope

new

pub fn new(weights: Vec<f64>) -> Self

Set complete rank weights, checked during evaluation and fitting.

weights

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

Configured rank weights, including the penalty strength.

Implementation of Clone

impl Clone for Slope

clone

fn clone(&self) -> Self

Implementation of Debug

impl Debug for Slope

fmt

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

Implementation of GapSafePenalty

impl GapSafePenalty for shrinkage::Slope

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<Slope> 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],
    _: &Slope,
    iteration: usize
) -> Result<(), FitError<<M as >::Error>>

set_screened

fn set_screened(&mut self, _: &[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: &Slope,
    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::Slope

AtStrength

type AtStrength = Slope;

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 Slope

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 Slope

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

State

type State = State;

Implementation of Freeze

impl !Freeze for Slope

Implementation of RefUnwindSafe

impl !RefUnwindSafe for Slope

Implementation of Send

impl Send for Slope

Implementation of Sync

impl !Sync for Slope

Implementation of Unpin

impl Unpin for Slope

Implementation of UnsafeUnpin

impl UnsafeUnpin for Slope

Implementation of UnwindSafe

impl UnwindSafe for Slope

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>