pub struct GroupLasso<A: Float + ScalarOperand + Debug> { /* private fields */ }Expand description
Group Lasso regularizer for structured sparsity
The Group Lasso penalty encourages entire groups of parameters to be zero, rather than individual parameters (as in standard L1/Lasso). This is useful when parameters have a natural grouping structure (e.g., features belonging to the same category, filters in a convolutional layer).
Penalty: lambda * sum_g(w_g * ||params[group_g]||_2)
where w_g is the weight for group g and ||.||_2 is the L2 norm.
§Examples
use scirs2_core::ndarray::Array1;
use optirs_core::regularizers::{GroupLasso, Regularizer};
// Create a Group Lasso regularizer with two groups
let regularizer = GroupLasso::new(0.1_f64)
.with_groups(vec![vec![0, 1, 2], vec![3, 4, 5]]);
let params = Array1::from_vec(vec![1.0, 2.0, 3.0, 0.0, 0.0, 0.0]);
let penalty = regularizer.penalty(¶ms).expect("penalty computation failed");Implementations§
Source§impl<A: Float + ScalarOperand + Debug> GroupLasso<A>
impl<A: Float + ScalarOperand + Debug> GroupLasso<A>
Sourcepub fn new(lambda: A) -> Self
pub fn new(lambda: A) -> Self
Create a new Group Lasso regularizer
§Arguments
lambda- Regularization strength (must be non-negative)
Sourcepub fn with_groups(self, groups: Vec<Vec<usize>>) -> Self
pub fn with_groups(self, groups: Vec<Vec<usize>>) -> Self
Set the groups for the regularizer (builder pattern)
§Arguments
groups- A vector of index sets, where each inner vector contains the parameter indices belonging to that group
Sourcepub fn with_group_weights(self, weights: Vec<A>) -> Self
pub fn with_group_weights(self, weights: Vec<A>) -> Self
Set per-group weights (builder pattern)
§Arguments
weights- A vector of weights, one per group. Must have the same length as the number of groups.
Sourcepub fn auto_groups(self, param_size: usize, group_size: usize) -> Self
pub fn auto_groups(self, param_size: usize, group_size: usize) -> Self
Automatically create equal-sized groups (builder pattern)
Partitions parameter indices [0, param_size) into groups of group_size.
The last group may be smaller if param_size is not evenly divisible.
§Arguments
param_size- Total number of parametersgroup_size- Number of parameters per group
Sourcepub fn num_groups(&self) -> usize
pub fn num_groups(&self) -> usize
Get the number of groups
Trait Implementations§
Source§impl<A: Clone + Float + ScalarOperand + Debug> Clone for GroupLasso<A>
impl<A: Clone + Float + ScalarOperand + Debug> Clone for GroupLasso<A>
Source§fn clone(&self) -> GroupLasso<A>
fn clone(&self) -> GroupLasso<A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<A: Debug + Float + ScalarOperand + Debug> Debug for GroupLasso<A>
impl<A: Debug + Float + ScalarOperand + Debug> Debug for GroupLasso<A>
Source§impl<A, D> Regularizer<A, D> for GroupLasso<A>
impl<A, D> Regularizer<A, D> for GroupLasso<A>
Auto Trait Implementations§
impl<A> Freeze for GroupLasso<A>where
A: Freeze,
impl<A> RefUnwindSafe for GroupLasso<A>where
A: RefUnwindSafe,
impl<A> Send for GroupLasso<A>where
A: Send,
impl<A> Sync for GroupLasso<A>where
A: Sync,
impl<A> Unpin for GroupLasso<A>where
A: Unpin,
impl<A> UnsafeUnpin for GroupLasso<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for GroupLasso<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
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.