pub struct ElasticNet<A: Float + Debug> { /* private fields */ }Expand description
ElasticNet regularization
Combines L1 and L2 regularization to get the benefits of both:
- L1 encourages sparsity (many parameters are exactly 0)
- L2 discourages large weights for more stable solutions
Penalty: l1_ratio * L1_penalty + (1 - l1_ratio) * L2_penalty
§Examples
use scirs2_core::ndarray::Array1;
use optirs_core::regularizers::{ElasticNet, Regularizer};
// Create an ElasticNet regularizer with strength 0.01 and l1_ratio 0.5
// (equal weight to L1 and L2)
let regularizer = ElasticNet::new(0.01, 0.5);
// Parameters and gradients
let params = Array1::from_vec(vec![0.5, -0.3, 0.0, 0.2]);
let mut gradients = Array1::from_vec(vec![0.1, 0.2, -0.3, 0.0]);
// Apply regularization
let penalty = regularizer.apply(¶ms, &mut gradients).unwrap();
// Gradients will be modified to include both L1 and L2 penalty gradientsImplementations§
Source§impl<A: Float + Debug + Send + Sync> ElasticNet<A>
impl<A: Float + Debug + Send + Sync> ElasticNet<A>
Sourcepub fn new(alpha: A, l1ratio: A) -> Self
pub fn new(alpha: A, l1ratio: A) -> Self
Create a new ElasticNet regularizer
§Arguments
alpha- Total regularization strengthl1_ratio- Mixing parameter (0 <= l1_ratio <= 1)- l1_ratio = 1: only L1 penalty
- l1_ratio = 0: only L2 penalty
Sourcepub fn set_params(&mut self, alpha: A, l1ratio: A) -> &mut Self
pub fn set_params(&mut self, alpha: A, l1ratio: A) -> &mut Self
Set the regularization parameters
§Arguments
alpha- Total regularization strengthl1_ratio- Mixing parameter (0 <= l1_ratio <= 1)
Trait Implementations§
Source§impl<A: Clone + Float + Debug> Clone for ElasticNet<A>
impl<A: Clone + Float + Debug> Clone for ElasticNet<A>
Source§fn clone(&self) -> ElasticNet<A>
fn clone(&self) -> ElasticNet<A>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<A, D> Regularizer<A, D> for ElasticNet<A>
impl<A, D> Regularizer<A, D> for ElasticNet<A>
impl<A: Copy + Float + Debug> Copy for ElasticNet<A>
Auto Trait Implementations§
impl<A> Freeze for ElasticNet<A>where
A: Freeze,
impl<A> RefUnwindSafe for ElasticNet<A>where
A: RefUnwindSafe,
impl<A> Send for ElasticNet<A>where
A: Send,
impl<A> Sync for ElasticNet<A>where
A: Sync,
impl<A> Unpin for ElasticNet<A>where
A: Unpin,
impl<A> UnwindSafe for ElasticNet<A>where
A: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.