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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
MDS<T>
- Implements
- 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
nComponentsintTarget dimensionality. Defaults to 2.
mdsTypeMDSTypeType of MDS algorithm. Defaults to Classical.
metricMDSMetricDistance metric. Defaults to Euclidean.
maxIterintMaximum iterations for non-metric MDS. Defaults to 300.
epsdoubleConvergence tolerance. Defaults to 1e-6.
normalizedboolWhether to normalize stress. Defaults to false.
randomStateint?Random seed for reproducibility.
columnIndicesint[]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
NComponents
Gets the number of components (dimensions).
public int NComponents { get; }
Property Value
Stress
Gets the final stress value (goodness of fit).
public double Stress { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits MDS and computes the embedding.
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>