Shrinkage

shrinkage::Masked

Shrinkage for Rust · rust · 0.3.0

pub struct Masked<P>

A complete penalty with explicit unpenalized coordinates.

true excludes a coordinate, and false retains its penalty. The mask must have one entry per optimization-scale coefficient, excluding any intercept. Parameters and mask length are checked during evaluation and fitting. Excluded coordinates contribute no penalty and are copied unchanged by the proximal map. The wrapper owns its mask and allocates no evaluation workspace.

use shrinkage::{L1, Masked, Penalty, ProximalPenalty};

let penalty = Masked::new(vec![true, false], L1::new(2.0));
assert_eq!(penalty.value(&[10.0, -3.0])?, 6.0);
let mut output = [0.0; 2];
penalty.prox(&[10.0, -3.0], 0.5, &mut output)?;
assert_eq!(output, [10.0, -2.0]);

A coupled penalty without an implemented restriction cannot be masked, even if it supplies a complete proximal map:

use shrinkage::{Masked, Slope};
let penalty = Masked::new(vec![true, false], Slope::new(vec![2.0, 1.0]));

Runtime selection must preserve the restricted capability before masking:

use shrinkage::{L1, Masked, ProximalPenalty};
let penalty: Box<dyn ProximalPenalty> = Box::new(L1::new(1.0));
let masked = Masked::new(vec![true, false], penalty);

Inherent implementation

impl<P: RestrictedProximalPenalty> Masked<P>

new

pub fn new(unpenalized: Vec<bool>, penalty: P) -> Self

Set the unpenalized mask and inner penalty, checked when used.

penalty

pub fn penalty(&self) -> &P

Borrow the complete inner penalty, including its strengths.

unpenalized

pub fn unpenalized(&self) -> &[bool]

One flag per coefficient; true marks an unpenalized coordinate.

Implementation of Clone

impl<P: core::clone::Clone> Clone for Masked<P>

clone

fn clone(&self) -> Self

Implementation of Debug

impl<P: core::fmt::Debug> Debug for Masked<P>

fmt

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

Implementation of Penalty

impl<P: RestrictedProximalPenalty> Penalty for Masked<P>

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<P: RestrictedProximalPenalty> ProximalPenalty for Masked<P>

prox

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

Implementation of Freeze

impl<P> Freeze for Masked<P> where P: Freeze

Implementation of RefUnwindSafe

impl<P> RefUnwindSafe for Masked<P> where P: RefUnwindSafe

Implementation of Send

impl<P> Send for Masked<P> where P: Send

Implementation of Sync

impl<P> Sync for Masked<P> where P: Sync

Implementation of Unpin

impl<P> Unpin for Masked<P> where P: Unpin

Implementation of UnsafeUnpin

impl<P> UnsafeUnpin for Masked<P> where P: UnsafeUnpin

Implementation of UnwindSafe

impl<P> UnwindSafe for Masked<P> where P: UnwindSafe

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>