optirs_core/regularizers/
mod.rs

1// Regularization techniques for machine learning
2//
3// This module provides various regularization techniques commonly used in
4// machine learning to prevent overfitting, such as L1 (Lasso), L2 (Ridge),
5// ElasticNet, and Dropout.
6
7use scirs2_core::ndarray::{Array, Dimension, ScalarOperand};
8use scirs2_core::numeric::Float;
9use std::fmt::Debug;
10
11use crate::error::Result;
12
13/// Trait for regularizers that can be applied to parameters and gradients
14pub trait Regularizer<A, D>
15where
16    A: Float + ScalarOperand + Debug,
17    D: Dimension,
18{
19    /// Apply regularization to parameters and gradients
20    ///
21    /// # Arguments
22    ///
23    /// * `params` - The parameters to regularize
24    /// * `gradients` - The gradients to modify
25    ///
26    /// # Returns
27    ///
28    /// The regularization penalty value
29    fn apply(&self, params: &Array<A, D>, gradients: &mut Array<A, D>) -> Result<A>;
30
31    /// Compute the regularization penalty value
32    ///
33    /// # Arguments
34    ///
35    /// * `params` - The parameters to compute the penalty for
36    ///
37    /// # Returns
38    ///
39    /// The regularization penalty value
40    fn penalty(&self, params: &Array<A, D>) -> Result<A>;
41}
42
43mod activity;
44mod dropconnect;
45mod dropout;
46mod elastic_net;
47mod entropy;
48mod l1;
49mod l2;
50mod label_smoothing;
51mod manifold;
52mod mixup;
53mod orthogonal;
54mod shakedrop;
55mod spatial_dropout;
56mod spectral_norm;
57mod stochastic_depth;
58mod weight_standardization;
59
60// Re-export regularizers
61pub use activity::{ActivityNorm, ActivityRegularization};
62pub use dropconnect::DropConnect;
63pub use dropout::Dropout;
64pub use elastic_net::ElasticNet;
65pub use entropy::{EntropyRegularization, EntropyRegularizerType};
66pub use l1::L1;
67pub use l2::L2;
68pub use label_smoothing::LabelSmoothing;
69pub use manifold::ManifoldRegularization;
70pub use mixup::{CutMix, MixUp};
71pub use orthogonal::OrthogonalRegularization;
72pub use shakedrop::ShakeDrop;
73pub use spatial_dropout::{FeatureDropout, SpatialDropout};
74pub use spectral_norm::SpectralNorm;
75pub use stochastic_depth::StochasticDepth;
76pub use weight_standardization::WeightStandardization;