pub struct Regularizer<const P: usize> { /* private fields */ }Expand description
A weighted regularization term.
This can be interpreted as a prior of the form
f(\vec{x}) = \frac{p\lambda^{1/p}}{2\Gamma(1/p)}e^{-\frac{\lambda|\vec{x}|^p}}which becomes a Laplace distribution for $p=1$ and a Gaussian for $p=2$. These are commonly
interpreted as $\ell_p$ regularizers for linear regression models, with $p=1$ and $p=2$
corresponding to LASSO and ridge regression, respectively. When used in nonlinear regression,
these should be interpeted as the prior listed above when used in maximum a posteriori (MAP)
estimation. Explicitly, when the logarithm is taken, this term becomes
\lambda \left(\sum_{j} w_j |x_j|^p\right)^{1/p}plus some additional constant terms which do not depend on free parameters.
Weights can be specified to vary the influence of each parameter used in the regularization.
These weights are typically assigned by first fitting without a regularization term to obtain
parameter values $\vec{\beta}$, choosing a value $\gamma>0$, and setting the weights to
$\vec{w} = 1/|\vec{\beta}|^\gamma$ according to a paper by Zou1.
Implementations§
Source§impl<const P: usize> Regularizer<P>
impl<const P: usize> Regularizer<P>
Sourcepub fn new<T, U, F>(
parameters: T,
lambda: Float,
weights: Option<F>,
) -> Result<Box<Self>, LadduError>
pub fn new<T, U, F>( parameters: T, lambda: Float, weights: Option<F>, ) -> Result<Box<Self>, LadduError>
Create a new Regularizer term from a list of parameter names, a nonnegative
regularization parameter $\lambda$, and an optional list of weights which scale the
influence of each parameter in the regularization term. If not set, the weights will
default to unity.
§Errors
This method will return a LadduError if the number of parameters and weights are not equal.
Trait Implementations§
Source§impl<const P: usize> Clone for Regularizer<P>
impl<const P: usize> Clone for Regularizer<P>
Source§fn clone(&self) -> Regularizer<P>
fn clone(&self) -> Regularizer<P>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl LikelihoodTerm for Regularizer<1>
impl LikelihoodTerm for Regularizer<1>
Source§fn evaluate(&self, parameters: &[Float]) -> Float
fn evaluate(&self, parameters: &[Float]) -> Float
Source§fn evaluate_gradient(&self, parameters: &[Float]) -> DVector<Float>
fn evaluate_gradient(&self, parameters: &[Float]) -> DVector<Float>
Source§fn parameters(&self) -> Vec<String>
fn parameters(&self) -> Vec<String>
LikelihoodTerm::evaluate.Source§impl LikelihoodTerm for Regularizer<2>
impl LikelihoodTerm for Regularizer<2>
Source§fn evaluate(&self, parameters: &[Float]) -> Float
fn evaluate(&self, parameters: &[Float]) -> Float
Source§fn evaluate_gradient(&self, parameters: &[Float]) -> DVector<Float>
fn evaluate_gradient(&self, parameters: &[Float]) -> DVector<Float>
Source§fn parameters(&self) -> Vec<String>
fn parameters(&self) -> Vec<String>
LikelihoodTerm::evaluate.Auto Trait Implementations§
impl<const P: usize> Freeze for Regularizer<P>
impl<const P: usize> RefUnwindSafe for Regularizer<P>
impl<const P: usize> Send for Regularizer<P>
impl<const P: usize> Sync for Regularizer<P>
impl<const P: usize> Unpin for Regularizer<P>
impl<const P: usize> UnwindSafe for Regularizer<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.