Table of Contents

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

T

The numeric type for calculations (e.g., float, double).

Inheritance
TransformerBase<T, Matrix<T>, Matrix<T>>
TriMAP<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
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

nComponents int

Target dimensionality. Defaults to 2.

nInliers int

Number of nearest neighbors for triplet generation. Defaults to 10.

nOutliers int

Number of outliers per point. Defaults to 5.

nRandom int

Number of random triplets per point. Defaults to 3.

nIter int

Number of optimization iterations. Defaults to 400.

learningRate double

Learning rate for optimization. Defaults to 100. Higher values may cause instability.

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[,]

NComponents

Gets the number of components (dimensions).

public int NComponents { get; }

Property Value

int

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits TriMAP 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>