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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
SpectralEmbedding<T>
- Implements
- 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
nComponentsintTarget dimensionality. Defaults to 2.
affinitySpectralAffinityHow to construct the affinity matrix. Defaults to NearestNeighbors.
gammadouble?Kernel coefficient for RBF. If null, uses 1/n_features.
nNeighborsintNumber of neighbors for NN affinity. Defaults to 10.
randomStateint?Random seed for reproducibility.
columnIndicesint[]The column indices to use, or null for all columns.
Properties
Affinity
Gets the affinity type.
public SpectralAffinity Affinity { get; }
Property Value
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
NComponents
Gets the number of components.
public int NComponents { get; }
Property Value
NNeighbors
Gets the number of neighbors for nearest neighbors affinity.
public int NNeighbors { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits Spectral Embedding by computing the graph Laplacian eigenvectors.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Returns the embedding computed during Fit.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>