Table of Contents

Class LogScaler<T>

Namespace
AiDotNet.Preprocessing.Scalers
Assembly
AiDotNet.dll

Applies logarithmic transformation to features, useful for data spanning multiple orders of magnitude.

public class LogScaler<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>>
LogScaler<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

Log scaling transforms data using natural logarithm, which compresses the range of values. It shifts negative values to ensure all inputs are positive, then applies log scaling. This is particularly useful for exponentially distributed data.

For Beginners: Log normalization measures percentages rather than absolute amounts: - With regular measurement, going from 1 to 10 and from 10 to 100 look very different - With logarithmic measurement, both represent a "10× increase" and appear as equal steps

Example: [1,000, 10,000, 100,000, 1,000,000] becomes evenly spaced values.

Constructors

LogScaler(int[]?)

Creates a new instance of LogScaler<T>.

public LogScaler(int[]? columnIndices = null)

Parameters

columnIndices int[]

The column indices to scale, or null for all columns.

Properties

Shift

Gets the shift applied to each feature to ensure positive values.

public Vector<T>? Shift { get; }

Property Value

Vector<T>

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Computes the shift and log range for each feature from the training data.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

The training data matrix where each column is a feature.

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 (LogScaler doesn't change number of features).

InverseTransformCore(Matrix<T>)

Reverses the log scaling transformation.

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

Parameters

data Matrix<T>

The scaled data.

Returns

Matrix<T>

The original-scale data.

TransformCore(Matrix<T>)

Transforms the data by applying log scaling.

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

Parameters

data Matrix<T>

The data to transform.

Returns

Matrix<T>

The log-scaled data normalized to [0, 1].