Shrinkage

shrinkage::Binomial

Shrinkage for Rust · rust · 0.3.0

pub struct Binomial<'a>

Bernoulli negative log likelihood with a logit link, averaged over rows.

Responses must be finite and lie in [0, 1]; fractional responses represent proportions with equal observation weights. The complete linear predictor includes an optional unpenalized intercept, fitted by default.

The predictor Hessian is diagonal with entries at most 1 / (4n). Consequently, for an optimization-scale design augmented with an intercept column, the coefficient gradient has Lipschitz constant at most ||[X, 1]||² / (4n). crate::ProximalGradient uses backtracking to enforce the corresponding quadratic upper bound without computing this norm. crate::Irls uses the exact diagonal predictor Hessian to construct weighted quadratic models solved by coordinate descent.

use faer::{Col, Mat};
use shrinkage::{Binomial, Problem, ProximalGradient, Ridge};
let x = Mat::from_fn(4, 1, |i, _| i as f64);
let y = [0.0, 0.0, 1.0, 1.0];
let fit = Problem::new(&x, Binomial::new(&y), Ridge::new(0.1))
    .fit_with(&ProximalGradient::<Col<f64>>::new())?;
// Predictions are logits; apply the logistic function for probabilities.
let logits = fit.predict(&x)?;

Inherent implementation

impl<'a> Binomial<'a>

fit_intercept

pub fn fit_intercept(self, enabled: bool) -> Self

Enable or disable the unpenalized fitted intercept.

Explicit column centering can still induce an original-scale intercept.

fits_intercept

pub fn fits_intercept(&self) -> bool

Whether fitting includes a free, unpenalized intercept.

new

pub fn new(response: &'a [f64]) -> Self

Borrow responses, fitting an intercept by default.

response

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

Borrow the observed responses.

Implementation of Clone

impl<'a> Clone for Binomial<'a>

clone

fn clone(&self) -> Self

Implementation of ConvexLink

impl ConvexLink<Binomial<'_>> for Logit

Implementation of ConvexLink

impl ConvexLink<Binomial<'_>> for Probit

Implementation of Copy

impl<'a> Copy for Binomial<'a>

Implementation of CrossValidationDatafit

impl CrossValidationDatafit for shrinkage::Binomial<'_>

WithResponse

type WithResponse<'a> = Binomial<'a>;

response

fn response(&self) -> &[f64]

supports_metric

fn supports_metric(&self, metric: ValidationMetric) -> bool

validate_training

fn validate_training(&self) -> Result<(), FitError>

validation_metric

fn validation_metric(&self) -> ValidationMetric

with_response

fn with_response<'a>(&self, response: &'a [f64]) -> Binomial<'a>

Implementation of Datafit

impl Datafit for Binomial<'_>

Error

type Error = FitError;

value

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

Implementation of Debug

impl<'a> Debug for Binomial<'a>

fmt

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

Implementation of DiagonalHessianDatafit

impl DiagonalHessianDatafit for Binomial<'_>

hessian_diagonal

fn hessian_diagonal(
    &self,
    predictor: &[f64],
    output: &mut [f64]
) -> Result<(), FitError>

Implementation of DifferentiableDatafit

impl DifferentiableDatafit for Binomial<'_>

fits_intercept

fn fits_intercept(&self) -> bool

gradient

fn gradient(
    &self,
    predictor: &[f64],
    output: &mut [f64]
) -> Result<(), FitError>

n_obs

fn n_obs(&self) -> usize

Implementation of GapSafeDatafit

impl GapSafeDatafit for Binomial<'_>

dual_candidate

fn dual_candidate(
    &self,
    predictor: &[f64],
    output: &mut [f64]
) -> Result<(), FitError>

dual_objective

fn dual_objective(&self, dual: &[f64]) -> Result<f64, FitError>

fenchel_gap

fn fenchel_gap(&self, predictor: &[f64], dual: &[f64]) -> Result<f64, FitError>

finalize_dual

fn finalize_dual(&self, dual: &mut [f64]) -> Result<(), FitError>

strong_concavity

fn strong_concavity(&self) -> f64

Implementation of HybridPathDatafit

impl HybridPathDatafit for shrinkage::Binomial<'_>

Outer

type Outer = Outer;

fit

fn fit<M, V, P>(
    &self,
    design: &mut NativeDesign<M, V>,
    penalty: &P,
    solver: &HybridCoordinateDescent<V>,
    threshold: f64,
    work: (&mut Workspace<P>, &mut <Self as >::Outer)
) -> Result<Solution, FitError<<M as >::Error>> where M: RawColumns<f64> + MatVecInto<V> + MatTransposeVecInto<V>, V: ProximalVector, P: ReducedCoordinatePenalty

outer

fn outer(n: usize, p: usize) -> <Self as >::Outer

path_deviance

fn path_deviance<P: ReducedCoordinatePenalty>(
    &self,
    _: &Workspace<P>,
    outer: &<Self as >::Outer
) -> Result<Option<f64>, FitError>

validate_solver

fn validate_solver<V>(
    &self,
    solver: &HybridCoordinateDescent<V>
) -> Result<f64, FitError>

Implementation of NullModelDatafit

impl NullModelDatafit for shrinkage::Binomial<'_>

deviance

fn deviance(&self, predictor: &[f64]) -> Result<Option<f64>, FitError>

null_intercepts

fn null_intercepts(&self) -> Result<Vec<f64>, FitError>

Implementation of QuadraticModelDatafit

impl QuadraticModelDatafit for Binomial<'_>

working_curvature

fn working_curvature(
    &self,
    predictor: &[f64],
    output: &mut [f64]
) -> Result<(), FitError>

Implementation of SmoothDatafit

impl SmoothDatafit for Binomial<'_>

gap_safe

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

Implementation of Freeze

impl<'a> Freeze for Binomial<'a>

Implementation of RefUnwindSafe

impl<'a> RefUnwindSafe for Binomial<'a>

Implementation of Send

impl<'a> Send for Binomial<'a>

Implementation of Sync

impl<'a> Sync for Binomial<'a>

Implementation of Unpin

impl<'a> Unpin for Binomial<'a>

Implementation of UnsafeUnpin

impl<'a> UnsafeUnpin for Binomial<'a>

Implementation of UnwindSafe

impl<'a> UnwindSafe for Binomial<'a>

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 PathDatafit

impl<D> PathDatafit for D where D: SmoothDatafit + NullModelDatafit + ?Sized

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>