Table of Contents

Class Normalizer<T>

Namespace
AiDotNet.Preprocessing.Scalers
Assembly
AiDotNet.dll

Normalizes samples (rows) individually to unit norm (L1, L2, or Max).

public class Normalizer<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>

Type Parameters

T

The numeric type for calculations (e.g., float, double).

Inheritance
TransformerBase<T, Matrix<T>, Matrix<T>>
Normalizer<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

Unlike scalers that operate on columns (features), this normalizer operates on rows (samples). Each sample is scaled to have a unit norm (length of 1) in the specified norm type. This is useful when the magnitude of samples varies but their direction matters.

For Beginners: This normalizer scales each row so its "length" equals 1: - L1 norm: The sum of absolute values equals 1 - L2 norm: The Euclidean length (sqrt of sum of squares) equals 1 - Max norm: The maximum absolute value equals 1

Example with L2 norm: [3, 4] has length 5, so it becomes [0.6, 0.8] (length = 1)

Constructors

Normalizer(NormType, int[]?)

Creates a new instance of Normalizer<T>.

public Normalizer(NormType normType = NormType.L2, int[]? columnIndices = null)

Parameters

normType NormType

The type of norm to use (L1, L2, or Max). Defaults to L2.

columnIndices int[]

The column indices to include in normalization, or null for all columns.

Properties

NormType

Gets the norm type used for normalization.

public NormType NormType { get; }

Property Value

NormType

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Remarks

Inverse transform is not supported because the original row norms are not stored.

Methods

FitCore(Matrix<T>)

Fits the normalizer to the training data.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

The training data matrix.

Remarks

Normalizer is stateless for transformation - fitting validates the data structure.

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)

Parameters

inputFeatureNames string[]

The input feature names.

Returns

string[]

The same feature names (Normalizer doesn't change number of features).

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported for sample normalization.

protected override Matrix<T> InverseTransformCore(Matrix<T> data)

Parameters

data Matrix<T>

The normalized data.

Returns

Matrix<T>

Never returns - always throws.

Exceptions

NotSupportedException

Always thrown because sample norms are not stored.

TransformCore(Matrix<T>)

Transforms the data by normalizing each row to unit norm.

protected override Matrix<T> TransformCore(Matrix<T> data)

Parameters

data Matrix<T>

The data to transform.

Returns

Matrix<T>

The normalized data where each row has unit norm.