Class GlobalContrastScaler<T>
- Namespace
- AiDotNet.Preprocessing.Scalers
- Assembly
- AiDotNet.dll
Scales features by adjusting contrast based on mean and standard deviation.
public class GlobalContrastScaler<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
GlobalContrastScaler<T>
- Implements
- Inherited Members
Remarks
Global contrast scaling transforms data using the formula: (x - mean) / (2 * stdDev) + 0.5 This centers values around 0.5 and typically results in values between 0 and 1.
For Beginners: This scaler improves the "contrast" of your data: - It centers values around 0.5 (the new average) - Values above average become > 0.5, below average become < 0.5 - Most values end up between 0 and 1
Example: [68, 70, 71, 69, 72] → [0.3, 0.5, 0.6, 0.4, 0.7] Now the differences between values are more visible.
Constructors
GlobalContrastScaler(int[]?)
Creates a new instance of GlobalContrastScaler<T>.
public GlobalContrastScaler(int[]? columnIndices = null)
Parameters
columnIndicesint[]The column indices to scale, or null for all columns.
Properties
Mean
Gets the mean for each feature computed during fitting.
public Vector<T>? Mean { get; }
Property Value
- Vector<T>
StdDev
Gets the standard deviation for each feature computed during fitting.
public Vector<T>? StdDev { get; }
Property Value
- Vector<T>
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Computes the mean and standard deviation for each feature from the training data.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<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
inputFeatureNamesstring[]The input feature names.
Returns
- string[]
The same feature names (GlobalContrastScaler doesn't change number of features).
InverseTransformCore(Matrix<T>)
Reverses the global contrast scaling transformation.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The scaled data.
Returns
- Matrix<T>
The original-scale data.
TransformCore(Matrix<T>)
Transforms the data by applying global contrast scaling.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>The data to transform.
Returns
- Matrix<T>
The scaled data with values typically between 0 and 1.