Class TSNE<T>
- Namespace
- AiDotNet.Preprocessing.DimensionalityReduction
- Assembly
- AiDotNet.dll
t-Distributed Stochastic Neighbor Embedding for visualization.
public class TSNE<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
-
TSNE<T>
- Implements
- Inherited Members
Remarks
t-SNE is a nonlinear dimensionality reduction technique well-suited for visualizing high-dimensional data in 2D or 3D space. It preserves local structure by keeping similar points close together.
The algorithm converts similarities between data points to joint probabilities and tries to minimize the divergence between probability distributions in high and low dimensional spaces.
For Beginners: t-SNE creates beautiful 2D/3D visualizations: - Points that are similar stay close together - Points that are different move apart - Great for exploring clusters in your data - Warning: Not for preserving global distances, just local neighborhoods - Warning: Results can vary with different random seeds
Constructors
TSNE(int, double, double, int, double, TSNEMetric, TSNEInitialization, int?, int[]?)
Creates a new instance of TSNE<T>.
public TSNE(int nComponents = 2, double perplexity = 30, double learningRate = 200, int nIter = 1000, double earlyExaggeration = 12, TSNEMetric metric = TSNEMetric.Euclidean, TSNEInitialization initialization = TSNEInitialization.Random, int? randomState = null, int[]? columnIndices = null)
Parameters
nComponentsintTarget dimensionality (usually 2 or 3). Defaults to 2.
perplexitydoubleBalance between local and global structure. Defaults to 30.
learningRatedoubleLearning rate for optimization. Defaults to 200.
nIterintNumber of optimization iterations. Defaults to 1000.
earlyExaggerationdoubleExaggeration factor for early iterations. Defaults to 12.
metricTSNEMetricDistance metric to use. Defaults to Euclidean.
initializationTSNEInitializationInitialization method. Defaults to Random.
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[,]
LearningRate
Gets the learning rate.
public double LearningRate { get; }
Property Value
Metric
Gets the distance metric.
public TSNEMetric Metric { get; }
Property Value
NComponents
Gets the number of components (dimensions).
public int NComponents { get; }
Property Value
Perplexity
Gets the perplexity parameter.
public double Perplexity { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits t-SNE 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>