Table of Contents

Class MDS<T>

Namespace
AiDotNet.Preprocessing.DimensionalityReduction
Assembly
AiDotNet.dll

Multidimensional Scaling for dimensionality reduction.

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

Remarks

MDS finds a low-dimensional embedding that preserves pairwise distances between points. Classical MDS uses eigendecomposition of the double-centered distance matrix. Non-metric MDS uses iterative optimization to preserve distance rankings.

MDS is useful for: - Visualizing similarity/dissimilarity data - Preserving pairwise relationships - When you have a distance matrix rather than feature vectors

For Beginners: MDS tries to place points in 2D/3D such that: - Points that were close in high-D stay close in low-D - Points that were far apart stay far apart - Unlike t-SNE/UMAP, MDS tries to preserve actual distances, not just neighborhoods

Classical MDS: Preserves exact distances (works well when data is linear) Non-metric MDS: Preserves distance rankings (more flexible, works better for complex data)

Constructors

MDS(int, MDSType, MDSMetric, int, double, bool, int?, int[]?)

Creates a new instance of MDS<T>.

public MDS(int nComponents = 2, MDSType mdsType = MDSType.Classical, MDSMetric metric = MDSMetric.Euclidean, int maxIter = 300, double eps = 1E-06, bool normalized = false, int? randomState = null, int[]? columnIndices = null)

Parameters

nComponents int

Target dimensionality. Defaults to 2.

mdsType MDSType

Type of MDS algorithm. Defaults to Classical.

metric MDSMetric

Distance metric. Defaults to Euclidean.

maxIter int

Maximum iterations for non-metric MDS. Defaults to 300.

eps double

Convergence tolerance. Defaults to 1e-6.

normalized bool

Whether to normalize stress. Defaults to false.

randomState int?

Random seed for reproducibility.

columnIndices int[]

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

Properties

Embedding

Gets the embedding result.

public double[,]? Embedding { get; }

Property Value

double[,]

MdsType

Gets the MDS type (classical or non-metric).

public MDSType MdsType { get; }

Property Value

MDSType

NComponents

Gets the number of components (dimensions).

public int NComponents { get; }

Property Value

int

Stress

Gets the final stress value (goodness of fit).

public double Stress { 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 MDS and computes the embedding.

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>