RegularizationBase<T, TInput, TOutput>
Base Classes · AiDotNet.Regularization
Provides a base implementation for regularization techniques used to prevent overfitting in machine learning models.
Implements: IRegularization<T, TInput, TOutput>
Known derived types: ElasticNetRegularization<T, TInput, TOutput>, L1Regularization<T, TInput, TOutput>, L2Regularization<T, TInput, TOutput>, NoRegularization<T, TInput, TOutput>
For Beginners
Think of regularization as adding “guardrails” to your model’s learning process.
Imagine training a model is like teaching a student:
- Without regularization, the student might memorize all the test answers without understanding the principles
- With regularization, we encourage the student to learn simpler, more general rules
This base class provides the framework that all specific regularization techniques build upon. Different regularization approaches (like L1, L2, or Elastic Net) are like different teaching strategies, but they all aim to help your model generalize better to new data.
For example:
- L1 regularization eliminates less important features
- L2 regularization makes all features less extreme
- Elastic Net combines both approaches
All of these approaches inherit from this base class, which provides the common structure they all share.
How It Works
RegularizationBase serves as an abstract foundation for implementing various regularization strategies. Regularization is a technique used to prevent overfitting by adding a penalty term to the loss function that discourages complex models. This base class defines the common interface and provides shared functionality for all regularization implementations.
Constructors
| Constructor | Summary |
|---|---|
RegularizationBase(RegularizationOptions regularizationOptions) |
Initializes a new instance of the RegularizationBase class with the specified options. |
Methods
| Method | Summary |
|---|---|
Matrix<T> Regularize(Matrix<T> data) |
Applies regularization to model coefficients. |
RegularizationOptions GetOptions() |
Gets the configuration options for this regularization technique. |
TOutput Regularize(TOutput gradient, TOutput coefficients) |
Vector-direct gradient-aware regularization overload — same semantics as Regularize but avoids the wrap/unwrap round-trip when both inputs are already flat vectors (the typical case inside a gradient-based optimizer’s per-batch step). |
Vector<T> Regularize(Vector<T> data) |
Applies regularization to model coefficients. |
Vector<T> Regularize(Vector<T> gradient, Vector<T> coefficients) |
Vector-direct gradient-aware regularization overload — same semantics as Regularize but avoids the wrap/unwrap round-trip when both inputs are already flat vectors (the typical case inside a gradient-based optimizer’s per-batch step). |