Table of Contents

Class BaseRegularizer

Namespace
NeuralNetworks.Regularization
Assembly
NeuralNetworks.dll

Provides a base implementation of IRegularizer for applying regularization updates and optionally reporting a regularization penalty in the loss.

public abstract class BaseRegularizer : IRegularizer
Inheritance
BaseRegularizer
Implements
Derived
Inherited Members

Remarks

Derived types implement CalculatePenaltyCore(ReadOnlySpan<float>) and can override gradient and parameter update hooks to define regularization behavior.

Constructors

BaseRegularizer(bool)

Provides a base implementation of IRegularizer for applying regularization updates and optionally reporting a regularization penalty in the loss.

protected BaseRegularizer(bool reportPenaltyInLoss)

Parameters

reportPenaltyInLoss bool

Indicates whether the regularization penalty is included when reporting loss during training.

Remarks

Derived types implement CalculatePenaltyCore(ReadOnlySpan<float>) and can override gradient and parameter update hooks to define regularization behavior.

Properties

ReportPenaltyInLoss

Gets a value indicating whether a penalty is reported as a loss.

public bool ReportPenaltyInLoss { get; }

Property Value

bool

Remarks

When it is true, the regularization penalty is intended to be included in the reported training loss; otherwise, regularization affects gradients without changing the reported loss value.

Methods

ApplyGradientCore(ReadOnlySpan<float>, Span<float>)

Applies a gradient update to the specified parameter span using the corresponding gradient span.

protected virtual void ApplyGradientCore(ReadOnlySpan<float> paramSpan, Span<float> paramGradientSpan)

Parameters

paramSpan ReadOnlySpan<float>

The span of parameter values to update.

paramGradientSpan Span<float>

The span of gradient values corresponding to paramSpan.

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

param T

The parameter values to use for the update.

paramGradient T

The gradient values corresponding to param.

Type Parameters

T

The parameter container type that can be converted to spans of single-precision floating-point values.

Remarks

Both inputs are converted to spans and must have the same length.

CalculatePenaltyCore(ReadOnlySpan<float>)

protected virtual float CalculatePenaltyCore(ReadOnlySpan<float> paramSpan)

Parameters

paramSpan ReadOnlySpan<float>

Returns

float

ReportPenalty<T>(T)

Computes and returns the penalty for the specified parameter when penalty reporting is enabled.

public float ReportPenalty<T>(T param) where T : notnull

Parameters

param T

The parameter value to evaluate for penalty calculation.

Returns

float

The computed penalty value when reporting is enabled; otherwise, 0f.

Type Parameters

T

The type of the parameter to evaluate. Must be a non-null type.

UpdateParamsCore(Span<float>)

Updates parameter values in the specified span.

protected virtual void UpdateParamsCore(Span<float> paramSpan)

Parameters

paramSpan Span<float>

A span containing the parameter values to update.

Remarks

Override in a derived type to apply parameter updates in place.

UpdateParams<T>(T)

Updates parameter values from the specified input by converting it to a Span<T> and passing it to the core update routine.

public void UpdateParams<T>(T param) where T : notnull

Parameters

param T

The input containing parameter values to apply.

Type Parameters

T

The non-null input type that can be converted to a span of single-precision values.