Class CompositeRegularizer
- Namespace
- NeuralNetworks.Regularization
- Assembly
- NeuralNetworks.dll
Combines multiple regularizers into a single regularization pipeline.
public class CompositeRegularizer : IRegularizer
- Inheritance
-
CompositeRegularizer
- Implements
- Derived
- Inherited Members
Remarks
Applies regularizers in the order provided for gradient adjustment, penalty calculation, and parameter updates. Penalty reporting is enabled when at least one contained regularizer reports a penalty in the loss, and the reported penalty is the sum of all enabled regularizer penalties.
Constructors
CompositeRegularizer(params BaseRegularizer[])
public CompositeRegularizer(params BaseRegularizer[] regularizers)
Parameters
regularizersBaseRegularizer[]The regularizers to combine. They are applied in the given order when computing gradients and penalties.
Properties
ReportPenaltyInLoss
Indicates whether penalty is reported as a loss.
public bool ReportPenaltyInLoss { get; }
Property Value
Methods
ApplyGradient<T>(T, T)
Applies a gradient update using the specified parameter values and corresponding gradient values.
public void ApplyGradient<T>(T param, T paramGradient) where T : notnull
Parameters
paramTThe parameter value to adjust.
paramGradientTThe gradient of the parameter to adjust.
Type Parameters
TThe type of the parameter and gradient. Must be a non-null type.
Remarks
It calls the ApplyGradientCore(ReadOnlySpan<float>, Span<float>) method of each contained regularizer in the order they were provided, allowing for sequential gradient adjustments.
ReportPenalty<T>(T)
Calculates the total regularization penalty to include in the loss for the provided parameter values.
public float ReportPenalty<T>(T param) where T : notnull
Parameters
paramTThe parameter values used to evaluate regularization penalties.
Returns
- float
The sum of penalties from regularizers configured to report penalty in loss; otherwise
0.
Type Parameters
TThe parameter container type that can be converted to a read-only span of single-precision values.
Remarks
Returns 0 when penalty reporting in loss is disabled.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
UpdateParams<T>(T)
Updates all configured regularizers with the provided parameter values.
public void UpdateParams<T>(T param) where T : notnull
Parameters
paramTThe parameter data to convert and pass to each regularizer.
Type Parameters
TA non-null parameter container type supported by the parameter-to-span conversion routine.
Remarks
Converts the input to a Span<T> and forwards it to each regularizer in sequence.