Class TriMAP<T>
- Namespace
- AiDotNet.Preprocessing.DimensionalityReduction
- Assembly
- AiDotNet.dll
TriMAP: Large-scale Dimensionality Reduction Using Triplets.
public class TriMAP<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
-
TriMAP<T>
- Implements
- Inherited Members
Remarks
TriMAP is a dimensionality reduction method that uses triplet constraints to preserve both local and global structure. It outperforms t-SNE and UMAP on many datasets while being more robust to hyperparameter choices.
The algorithm: 1. Generate triplets (anchor, positive, negative) based on distance relationships 2. Initialize embedding using PCA 3. Optimize using triplet loss to preserve distance rankings 4. Weight triplets to balance local and global structure
For Beginners: TriMAP preserves distance relationships using triplets: - A triplet (i, j, k) means point i is closer to j than to k - Optimization ensures these relationships hold in the embedding - More accurate than t-SNE/UMAP for many datasets - Less sensitive to parameter tuning
Use cases:
- Large-scale visualization (millions of points)
- When t-SNE/UMAP produces poor results
- When you need faithful global structure
- Complex datasets with hierarchical structure
Constructors
TriMAP(int, int, int, int, int, double, int?, int[]?)
Creates a new instance of TriMAP<T>.
public TriMAP(int nComponents = 2, int nInliers = 10, int nOutliers = 5, int nRandom = 3, int nIter = 400, double learningRate = 100, int? randomState = null, int[]? columnIndices = null)
Parameters
nComponentsintTarget dimensionality. Defaults to 2.
nInliersintNumber of nearest neighbors for triplet generation. Defaults to 10.
nOutliersintNumber of outliers per point. Defaults to 5.
nRandomintNumber of random triplets per point. Defaults to 3.
nIterintNumber of optimization iterations. Defaults to 400.
learningRatedoubleLearning rate for optimization. Defaults to 100. Higher values may cause instability.
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[,]
NComponents
Gets the number of components (dimensions).
public int NComponents { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits TriMAP 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>