ggml_ot.data.TripletDataset

ggml_ot.data.TripletDataset#

class ggml_ot.data.TripletDataset(supports, distribution_labels, n_triplets=3, weights=None, covariances=None, identical_supports=False, label_type='categorical', distribution_labels_str=None, **kwargs)[source]#

Dataset to train GGML based on array data.

This class stores a collection of distributions (“supports”) and exposes the standardized interfaces used by ggml_ot.train(), ggml_ot.tune(), ggml_ot.test(), and ggml_ot.train_test(). Triplets (i, j, k) — where pair (i, j) should sit closer than pair (j, k) by margin alpha — are built per batch by ggml_ot.optimization.triplets.create_triplets() using categorical (equality-based) labels.

Parameters:
supports Sequence[np.ndarray]

Sequence of per-distribution supports. Each element is an array of points (for empirical distributions) or component means (for GMM-style representations).

distribution_labels Sequence[int] | np.ndarray

Labels identifying the class/group of each distribution.

n_triplets int, optional

Number of triplets to generate per “anchor” distribution (default: 3).

weights Sequence[np.ndarray] | None, optional

Per-distribution probability weights (e.g., cluster proportions) or None for uniform weights (default: None).

covariances Sequence[np.ndarray] | None, optional

Optional per-distribution covariance arrays when supports represent Gaussian mixture components (default: None).

identical_supports bool, optional

If True, indicates that all distributions share the same supports (e.g., identical component locations across distributions). This changes the __getitem__ return format and allows faster OT evaluation (default: False).

label_type {"categorical"}, optional

Supervision mode for the distribution labels (default: "categorical"). Only "categorical" (nominal class labels with equality-based triplets) is supported in this stable release; other values raise NotImplementedError.

distribution_labels_str Sequence | np.ndarray | None, optional

Original per-distribution labels for display/annotation, stored as strings. When None (default), derived by stringifying distribution_labels. Must align 1:1 with distribution_labels.

__init__(supports, distribution_labels, n_triplets=3, weights=None, covariances=None, identical_supports=False, label_type='categorical', distribution_labels_str=None, **kwargs)[source]#

Methods

__init__(supports, distribution_labels[, ...])

compute_OT([precomputed_distances, ...])

Compute the Optimal Transport distances between all distributions.

fit_gmm(*[, component_sharing, k_comps, ...])

Fit per-patient GMM parameters from a GGML dataset.

normalize()

test([ground_metric, knn_k])

Tests ground metric on a given dataset.

train([alpha, reg, reg_type, n_comps, lr, ...])

Perform supervised optimal transport by ground metric learning.

train_emd2([alpha, reg, reg_type, n_comps, ...])

Train GGML with exact OT (EMD2).

train_sinkhorn([alpha, reg, reg_type, ...])

Train GGML with Sinkhorn-regularized OT.

train_test([n_splits, train_size, ...])

Trains and cross-validates ground metrics on train-test splits.

tune([alpha, reg, reg_type, n_comps, ...])

Tune hyperparameters by performing a Grid Search and Cross-Validation.

validate_gmm(*[, gmm_key, patient_col, ...])

Run a one-call hold-out validation pass for a fitted GMM.

Attributes

covariances

dim

Dimensions of space underlying the distributions.

distribution_labels

Per-distribution labels, integer-encoded.

distribution_labels_plot

Per-distribution labels formatted for plotting (stringified for discrete legends).

distribution_labels_str

Original per-distribution labels, stringified, for annotations/display.

identical_supports

Flag as passed to the constructor.

label_type

Label supervision mode; only 'categorical' is supported.

map_A

Learned ground metric as a linear map (raises a warning if dataset is not trained yet).

points

points_labels

Returns list of the distribution_labels of all points concatenated over all distributions

supports

Stored supports.

w_theta

use map_A instead.

weights

Stored per-distribution weights (if provided).