- class ott.geometry.geometry.Geometry(cost_matrix=None, kernel_matrix=None, epsilon=None, relative_epsilon=None, scale_cost=1.0, src_mask=None, tgt_mask=None)#
Base class to define ground costs/kernels used in optimal transport.
Optimal transport problems are intrinsically geometric: they compute an optimal way to transport mass from one configuration onto another. To define what is meant by optimality of transport requires defining a cost, of moving mass from one among several sources, towards one out of multiple targets. These sources and targets can be provided as points in vectors spaces, grids, or more generally exclusively described through a (dissimilarity) cost matrix, or almost equivalently, a (similarity) kernel matrix.
Once that cost or kernel matrix is set, the
Geometryclass provides a basic operations to be run with the Sinkhorn algorithm.
None]) – Regularization parameter. If
relative_epsilon = Trueor
relative_epsilon = None, this defaults to the value computed in
mean_cost_matrix/ 20. If passed as a
float, then the regularizer that is ultimately used is either that
relative_epsilon = Falseor
None) or that
relative_epsilon = True). Look for
Epsilonwhen passed as a scheduler.
bool]) – when False, the parameter
epsilonspecifies the value of the entropic regularization parameter. When True,
epsilonrefers to a fraction of the
mean_cost_matrix, which is computed adaptively from data.
'median']]) – option to rescale the cost matrix. Implemented scalings are ‘median’, ‘mean’ and ‘max_cost’. Alternatively, a float factor can be given to rescale the cost such that
cost_matrix /= scale_cost. If True, use ‘mean’.
When defining a
cost_matrix, it is important to select an
epsilonregularization parameter that is meaningful. That parameter can be provided by the user, or assigned a default value through a simple rule, using the
apply_cost(arr[, axis, fn])
cost_matrixto array (vector or matrix).
apply_kernel(scaling[, eps, axis])
kernel_matrixon positive scaling vector.
apply_lse_kernel(f, g, eps[, vec, axis])
kernel_matrixin log domain.
Apply elementwise-square of cost matrix to array (vector or matrix).
apply_transport_from_potentials(f, g, vec[, ...])
Apply transport matrix computed from potentials to a (batched) vec.
apply_transport_from_scalings(u, v, vec[, axis])
Apply transport matrix computed from scalings to a (batched) vec.
Copy the epsilon parameters from another geometry.
marginal_from_potentials(f, g[, axis])
Output marginal of transportation matrix from potentials.
marginal_from_scalings(u, v[, axis])
Output marginal of transportation matrix from scalings.
mask(src_mask, tgt_mask[, mask_value])
Mask rows or columns of a geometry.
Compute dual potential vector from scaling vector.
Instantiate 2 (or 3) geometries to compute a Sinkhorn divergence.
Compute scaling vector from dual potential.
Modify how to rescale of the
subset(src_ixs, tgt_ixs, **kwargs)
Subset rows or columns of a geometry.
to_LRCGeometry([rank, tol, rng, scale])
Factorize the cost matrix using either SVD (full) or [Indyk et al., 2019].
Output transport matrix from potentials.
Output transport matrix from pair of scalings.
update_potential(f, g, log_marginal[, ...])
Carry out one Sinkhorn update for potentials, i.e. in log space.
update_scaling(scaling, marginal[, ...])
Carry out one Sinkhorn update for scalings, using kernel directly.
Check quickly if casting geometry as LRC makes sense.
Cost matrix, recomputed from kernel if only kernel was specified.
Output rank of cost matrix, if any was provided.
The data type.
Epsilon regularization value.
Compute and return inverse of scaling factor for cost matrix.
Whether geometry cost/kernel should be recomputed on the fly.
Whether cost is computed by taking squared Euclidean distance.
Whether geometry cost/kernel is a symmetric matrix.
Mean of the
Median of the
Shape of the geometry.
Mask of shape
Mask of shape