Table of Contents

Class TruncatedSVD<T>

Namespace
AiDotNet.Preprocessing.DimensionalityReduction
Assembly
AiDotNet.dll

Truncated Singular Value Decomposition for dimensionality reduction.

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

Remarks

TruncatedSVD performs dimensionality reduction by computing the truncated singular value decomposition. Unlike PCA, it does not center the data, making it suitable for sparse matrices (e.g., TF-IDF from text).

Also known as Latent Semantic Analysis (LSA) when applied to document-term matrices.

For Beginners: SVD is similar to PCA but: - Doesn't center the data (preserves sparsity in sparse matrices) - Can be more memory-efficient for large sparse datasets - Often used for text analysis (finding hidden topics in documents)

Example: In text analysis, TruncatedSVD can find that "car" and "automobile" are related even if they never appear together in the same document.

Constructors

TruncatedSVD(int, int, int, int[]?)

Creates a new instance of TruncatedSVD<T>.

public TruncatedSVD(int nComponents = 2, int nIterations = 5, int randomState = 0, int[]? columnIndices = null)

Parameters

nComponents int

Number of components to keep. Defaults to 2.

nIterations int

Number of iterations for randomized SVD. Defaults to 5.

randomState int

Random seed for reproducibility. Defaults to 0.

columnIndices int[]

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

Properties

Components

Gets the components (right singular vectors).

public double[,]? Components { get; }

Property Value

double[,]

ExplainedVariance

Gets the explained variance for each component.

public double[]? ExplainedVariance { get; }

Property Value

double[]

ExplainedVarianceRatio

Gets the explained variance ratio for each component.

public double[]? ExplainedVarianceRatio { get; }

Property Value

double[]

NComponents

Gets the number of components.

public int NComponents { get; }

Property Value

int

NIterations

Gets the number of iterations for randomized SVD.

public int NIterations { get; }

Property Value

int

SingularValues

Gets the singular values.

public double[]? SingularValues { get; }

Property Value

double[]

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits TruncatedSVD by computing singular value decomposition.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

The training data matrix.

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

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

Parameters

inputFeatureNames string[]

Returns

string[]

InverseTransformCore(Matrix<T>)

Transforms data back to original space.

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

Parameters

data Matrix<T>

The transformed data.

Returns

Matrix<T>

Data in original feature space.

TransformCore(Matrix<T>)

Transforms the data by projecting onto singular vectors.

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

Parameters

data Matrix<T>

The data to transform.

Returns

Matrix<T>

The transformed data.