Table of Contents

Class SpectralEmbedding<T>

Namespace
AiDotNet.Preprocessing.DimensionalityReduction
Assembly
AiDotNet.dll

Spectral Embedding for nonlinear dimensionality reduction.

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

Remarks

Spectral Embedding forms an affinity matrix from the data and computes the eigenvectors of the graph Laplacian. This provides a low-dimensional representation that preserves local connectivity.

The algorithm constructs a similarity graph and uses spectral decomposition of the Laplacian matrix to find coordinates that respect graph structure.

For Beginners: Spectral Embedding uses graph theory: - Build a graph where similar points are connected - Use the graph's structure to find good coordinates - Similar to what's used in spectral clustering - Good for data with cluster structure

Constructors

SpectralEmbedding(int, SpectralAffinity, double?, int, int?, int[]?)

Creates a new instance of SpectralEmbedding<T>.

public SpectralEmbedding(int nComponents = 2, SpectralAffinity affinity = SpectralAffinity.NearestNeighbors, double? gamma = null, int nNeighbors = 10, int? randomState = null, int[]? columnIndices = null)

Parameters

nComponents int

Target dimensionality. Defaults to 2.

affinity SpectralAffinity

How to construct the affinity matrix. Defaults to NearestNeighbors.

gamma double?

Kernel coefficient for RBF. If null, uses 1/n_features.

nNeighbors int

Number of neighbors for NN affinity. Defaults to 10.

randomState int?

Random seed for reproducibility.

columnIndices int[]

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

Properties

Affinity

Gets the affinity type.

public SpectralAffinity Affinity { get; }

Property Value

SpectralAffinity

AffinityMatrix

Gets the affinity matrix.

public double[,]? AffinityMatrix { get; }

Property Value

double[,]

Embedding

Gets the embedding result.

public double[,]? Embedding { get; }

Property Value

double[,]

Gamma

Gets the gamma parameter for RBF kernel.

public double Gamma { get; }

Property Value

double

NComponents

Gets the number of components.

public int NComponents { get; }

Property Value

int

NNeighbors

Gets the number of neighbors for nearest neighbors affinity.

public int NNeighbors { get; }

Property Value

int

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits Spectral Embedding by computing the graph Laplacian eigenvectors.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

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

Parameters

inputFeatureNames string[]

Returns

string[]

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported.

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

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Returns the embedding computed during Fit.

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

Parameters

data Matrix<T>

Returns

Matrix<T>