API

geomloss - Geometric Loss functions, with full support of PyTorch’s autograd engine:

The SamplesLoss class implements a collection of geometric loss functions between point clouds, including the Sinkhorn divergence and kernel MMDs. It can be used as a loss function in a PyTorch training loop.

SamplesLoss([loss, p, blur, reach, ...])

Creates a criterion that computes distances between sampled measures on a vector space.

The geomloss.ot submodule, introduced in 2026, now provides a modern interface to our scalable optimal transport solvers. It is compatible with the Python Optimal Transport library and provides a convenient access to optimal transport plans and potentials.

Warning

The API of geomloss.ot is still in development and may change in future releases. We welcome any feedback and suggestions for improvement.

The ot.solve() and ot.solve_batch() functions handle user-defined cost matrices \(C_{ij}\). They return an ot.OTResultMatrix object which stores the optimal transport plan, potentials, and other useful quantities.

ot.solve(C, *, reg[, a, b, unbalanced, ...])

Solves an optimal transport problem with an explicit cost matrix.

ot.solve_batch(C, *, reg[, a, b, ...])

Batched version of solve(), which can solve multiple OT problems in parallel.

ot.OTResultMatrix(*, a, b, C, potentials, ...)

Stores the result of an optimal transport problem computed using an explicit cost matrix.

The ot.solve_sample() handles the case where the cost matrix \(C_{ij}\) derives from a cost function \(c(x_i, y_j)\) that is evaluated on points \(x_i\) and \(y_j\) in some vector space – for instance, the squared Euclidean distance \(c(x_i, y_j) = \|x_i-y_j\|^2\). It is most similar to SamplesLoss and returns an ot.OTResultSample object.

ot.solve_sample(X_a, X_b[, a, b, cost, ...])

Solves an optimal transport problem between point clouds.

ot.OTResultSample(*, X_a, X_b, a, b, C, ...)

Stores the result of an optimal transport problem computed using point positions.

Note that both ot.OTResultMatrix and ot.OTResultSample provide efficient access to transfer operators via the ot.LinearOperator class:

ot.LinearOperator(*, matmat, rmatmat, ...)

Linear operator that can be applied to arrays, without being explicitly instantiated as a matrix.

Note

We will soon add support for measures defined on regular grids, such as 2D and 3D density images, as well as Wasserstein barycenters and solutions of the Gromov-Wasserstein problem.

class geomloss.SamplesLoss(loss='sinkhorn', p=2, blur=0.05, reach=None, diameter=None, scaling=0.5, truncate=5, cost=None, kernel=None, cluster_scale=None, debias=True, potentials=False, verbose=False, backend='auto')[source]

Creates a criterion that computes distances between sampled measures on a vector space.

Warning

If loss is "sinkhorn" and reach is None (balanced Optimal Transport), the resulting routine will expect measures whose total masses are equal with each other.

Parameters:
  • loss (string, default = "sinkhorn") –

    The loss function to compute. The supported values are:

    • "sinkhorn": (Un-biased) Sinkhorn divergence, which interpolates between Wasserstein (blur=0) and kernel (blur= \(+\infty\) ) distances.

    • "hausdorff": Weighted Hausdorff distance, which interpolates between the ICP loss (blur=0) and a kernel distance (blur= \(+\infty\) ).

    • "energy": Energy Distance MMD, computed using the kernel \(k(x,y) = -\|x-y\|_2\).

    • "gaussian": Gaussian MMD, computed using the kernel \(k(x,y) = \exp ( -\|x-y\|_2^2 \,/\, 2\sigma^2)\) of standard deviation \(\sigma\) = blur.

    • "laplacian": Laplacian MMD, computed using the kernel \(k(x,y) = \exp ( -\|x-y\|_2 \,/\, \sigma)\) of standard deviation \(\sigma\) = blur.

  • p (int, default 2) –

    If loss is "sinkhorn" or "hausdorff", specifies the ground cost function between points. The supported values are:

    • p = 1: \(~~C(x,y) ~=~ \|x-y\|_2\).

    • p = 2: \(~~C(x,y) ~=~ \tfrac{1}{2}\|x-y\|_2^2\).

  • blur (float, default .05) –

    The finest level of detail that should be handled by the loss function - in order to prevent overfitting on the samples’ locations.

    • If loss is "gaussian" or "laplacian", it is the standard deviation \(\sigma\) of the convolution kernel.

    • If loss is "sinkhorn" or "hausdorff", it is the typical scale \(\sigma\) associated to the temperature \(\varepsilon = \sigma^p\). The default value of .05 is sensible for input measures that lie in the unit square/cube.

    Note that the Energy Distance is scale-equivariant, and won’t be affected by this parameter.

  • reach (float, default None) – If loss is "sinkhorn" or "hausdorff", specifies the typical scale \(\tau\) associated to the constraint strength \(\rho = \tau^p\). If reach is not None, the resulting routine will be an unbalanced OT loss, which can handle measures with different total masses. If reach is None, \(\rho = +\infty\) and the resulting routine will be a balanced OT loss, which expects measures with the same total mass.

  • diameter (float, default None) – A rough indication of the maximum distance between points, which is used to tune the \(\varepsilon\)-scaling descent and provide a default heuristic for clustering multiscale schemes. If None, a conservative estimate will be computed on-the-fly.

  • scaling (float, default .5) – If loss is "sinkhorn", specifies the ratio between successive values of \(\sigma=\varepsilon^{1/p}\) in the \(\varepsilon\)-scaling descent. This parameter allows you to specify the trade-off between speed (scaling < .4) and accuracy (scaling > .9).

  • truncate (float, default None) – If backend is "multiscale", specifies the effective support of a Gaussian/Laplacian kernel as a multiple of its standard deviation. If truncate is not None, kernel truncation steps will assume that \(\exp(-x/\sigma)\) or \(\exp(-x^2/2\sigma^2)\) are zero when \(\|x\| \,>\, \text{truncate}\cdot \sigma\). If truncate is None, no truncation will be applied, and the resulting routines will be exact.

  • cost (function or string, default None) –

    if loss is "sinkhorn" or "hausdorff", specifies the cost function that should be used instead of \(\tfrac{1}{p}\|x-y\|^p\):

    • If backend is "tensorized", cost should be a python function that takes as input a (B,N,D) torch Tensor x, a (B,M,D) torch Tensor y and returns a batched Cost matrix as a (B,N,M) Tensor.

    • Otherwise, if backend is "online" or "multiscale", cost should be a KeOps formula, given as a string, with variables X and Y. The default values are "Norm2(X-Y)" (for p = 1) and "(SqDist(X,Y) / IntCst(2))" (for p = 2).

  • cluster_scale (float, default None) – If backend is "multiscale", specifies the coarse scale at which cluster centroids will be computed. If None, a conservative estimate will be computed from diameter and the ambient space’s dimension, making sure that memory overflows won’t take place.

  • debias (bool, default True) – If loss is "sinkhorn", specifies if we should compute the unbiased Sinkhorn divergence instead of the classic, entropy-regularized “SoftAssign” loss.

  • potentials (bool, default False) – When this parameter is set to True, the SamplesLoss layer returns a pair of optimal dual potentials \(F\) and \(G\), sampled on the input measures, instead of differentiable scalar value. These dual vectors \((F(x_i))\) and \((G(y_j))\) are encoded as Torch tensors, with the same shape as the input weights \((\alpha_i)\) and \((\beta_j)\).

  • verbose (bool, default False) – If backend is "multiscale", specifies whether information on the clustering and \(\varepsilon\)-scaling descent should be displayed in the standard output.

  • backend (string, default = "auto") –

    The implementation that will be used in the background; this choice has a major impact on performance. The supported values are:

    • "auto": Choose automatically, using a simple heuristic based on the inputs’ shapes.

    • "tensorized": Relies on a full cost/kernel matrix, computed once and for all and stored on the device memory. This method is fast, but has a quadratic memory footprint and does not scale beyond ~5,000 samples per measure.

    • "online": Computes cost/kernel values on-the-fly, leveraging online map-reduce CUDA routines provided by the pykeops library.

    • "multiscale": Fast implementation that scales to millions of samples in dimension 1-2-3, relying on the block-sparse reductions provided by the pykeops library.

geomloss.ot.solve(C, *, reg, a=None, b=None, unbalanced=None, unbalanced_type='KL', method='auto', max_iter=None, tol=None)[source]

Solves an optimal transport problem with an explicit cost matrix.

Warning

The interface of this solver is still in development and may change in future releases. We welcome any feedback and suggestions for improvement.

We focus on entropy-regularized OT and support both the balanced setting (with strict transport constraints) and the unbalanced setting (with softer constraints on the marginals of the transport plan).

Given a source measure \(\alpha\) sampled with \(N\) points, a target measure \(\beta\) sampled with \(M\) points and a \(N\)-by-\(M\) cost matrix \(C\), the primal formulation of the problem \(\text{OT}_{\varepsilon, \rho}(\alpha, \beta)\) reads:

\[\min_{\pi \in \mathbb{R}_+^{N \times M}} \sum_{i=1}^N \sum_{j=1}^M C_{ij} \pi_{ij} + \varepsilon \text{KL}(\pi, \alpha \otimes \beta) + \text{D}_\rho(\pi 1_M, \alpha) + \text{D}_\rho(\pi^\top 1_N, \beta)~,\]

where:

  • \(\pi\) is the transport plan, a non-negative matrix of shape \((N,M)\).

  • \(\varepsilon > 0\) is the regularization strength or temperature.

  • \(\text{KL}(\pi, \alpha \otimes \beta)\) is the relative entropy of \(\pi\) with respect to the reference product measure \(\alpha \otimes \beta\):

\[\text{KL}(\pi, \alpha \otimes \beta) = \sum_{i=1}^N \sum_{j=1}^M \pi_{ij} \log\left( \frac{\pi_{ij}}{\alpha_i \beta_j} \right) - \pi_{ij} + \alpha_i \beta_j~.\]
  • \(\text{D}_\rho\) is a penalty on the marginal constraints, weighted by a positive parameter \(\rho\).

    • If \(\rho = +\infty\), we are in the balanced setting and \(\text{D}_{\rho}\) encodes a hard constraint on the marginals of \(\pi\): \(\pi 1_M = \alpha\) and \(\pi^\top 1_N = \beta\).

    • If \(\rho < +\infty\), we are in the unbalanced setting and \(\text{D}_\rho\) encodes a softer penalty on the marginal constraints, which allows for partial transport of the source measure \(\alpha\) onto the target \(\beta\). Currently, we only support the Kullback-Leibler divergence as unbalanced OT penalty, in which case we have:

\[\begin{split}\text{D}_\rho(\pi 1_M, \alpha) = \rho \cdot \text{KL}(\pi 1_M, \alpha)~,~ \\ \text{D}_\rho(\pi^\top 1_N, \beta) = \rho \cdot \text{KL}(\pi^\top 1_N, \beta)~.\end{split}\]
Parameters:
  • C ((N,M) array-like) – Cost matrix: \(C_{ij}\) denotes the cost of transporting a unit of mass from point \(x_i\) in the source measure \(\alpha\) to point \(y_j\) in the target measure \(\beta\).

  • reg (float > 0) – Regularization strength or temperature \(\varepsilon\). It should be understood as a fuzziness parameter that is applied to the cost matrix: \(\varepsilon = \max_{i,j} C_{ij} - \min_{i,j} C_{ij}\) corresponds to a very fuzzy problem, and leads to an optimal transport plan that is close to the product measure \(\alpha \otimes \beta\). On the other hand, \(\varepsilon \rightarrow 0\) corresponds to the original cost matrix, without any fuzziness, and leads to a sparse optimal transport plan. In practice, we recommend using a value of \(\varepsilon\) that is small compared to the scale of the cost matrix, but not too small to avoid numerical issues. A good default value is \(\varepsilon = 0.001 \cdot (\max_{i,j} C_{ij} - \min_{i,j} C_{ij})\).

  • a ((N,) array-like >= 0, default: None) – First marginal: \(\alpha_i\) denotes the mass associated to point \(x_i\) in the source measure \(\alpha\). If not provided, we assume that \(a\) is the uniform distribution on \(N\) points, i.e. \(\alpha_i = 1/N\) for all \(i\).

  • b ((M,) array-like >= 0, default: None) – Second marginal: \(\beta_j\) denotes the mass associated to point \(y_j\) in the target measure \(\beta\). If not provided, we assume that \(b\) is the uniform distribution on \(M\) points, i.e. \(\beta_j = 1/M\) for all \(j\).

  • unbalanced (float > 0 or None, default: None) – Scaling factor \(\rho\) for the unbalanced OT penalty on the marginal constraints. If unbalanced is None, we solve the balanced OT problem and look for a full transport of the source marginal \(\alpha\) onto the target \(\beta\). If unbalanced is a positive float \(\rho > 0\), we solve an unbalanced OT problem where the marginal constraints are relaxed and penalized with a soft penalty parameterized by \(\rho\).

  • unbalanced_type (Literal['KL'], default: 'KL') – Type of unbalanced OT penalty to use when unbalanced is not None. Currently, we only support the Kullback-Leibler divergence "KL", also known as the relative entropy.

  • method (Literal['auto'], default: 'auto') – Optimization method to use. Currently, we only support the symmetrized Sinkhorn algorithm with annealing, which is activated by the keyword "auto".

  • max_iter (int > 0 or None, default: None) – Maximum number of iterations for the optimization algorithm. If None, the algorithm runs until convergence.

  • tol (float > 0 or None, default: None) – Tolerance for convergence. If None, we use a default tolerance based on the regularization strength \(\varepsilon\) and the scale of the cost matrix \(C\).

Returns:

An object containing the optimal transport plan, the dual potentials and other related quantities as attributes.

Return type:

OTResultMatrix

Examples

from geomloss import ot

# Solve a balanced, 2x3 OT problem with entropic regularization:
solution = ot.solve(
    C=[[0., 1., 4.],
       [2., 1., 0.]],
    a=[2, 2],
    b=[1, 1, 2],
    reg=0.001,
    max_iter=100,
)
print(solution.plan)
[[1. 1. 0.]
 [0. 0. 2.]]
print(f"{solution.value:.3f}")
0.997
geomloss.ot.solve_batch(C, *, reg, a=None, b=None, unbalanced=None, unbalanced_type='KL', method='auto', max_iter=None, tol=None)[source]

Batched version of solve(), which can solve multiple OT problems in parallel.

Warning

The interface of this solver is still in development and may change in future releases. We welcome any feedback and suggestions for improvement.

Parameters:
  • C ((B,N,M) array-like) – Batch of \(B\) cost matrices: \(C_{ij}^{(b)}\) denotes the cost of transporting a unit of mass from point \(x_i\) in the source measure \(\alpha^{(b)}\) to point \(y_j\) in the target measure \(\beta^{(b)}\) for the \(b\)-th OT problem in the batch.

  • a ((B,N) array-like >= 0, default: None) – Batch of \(B\) first marginals: \(\alpha_i^{(b)}\) denotes the mass associated to point \(x_i\) in the source measure \(\alpha^{(b)}\) for the \(b\)-th OT problem in the batch. If not provided, we assume that \(a\) is the uniform distribution on \(N\) points for each problem in the batch, i.e. \(\alpha_i^{(b)} = 1/N\) for all \(i\) and \(b\).

  • b ((B,M) array-like >= 0, default: None) – Batch of \(B\) second marginals: \(\beta_j^{(b)}\) denotes the mass associated to point \(y_j\) in the target measure \(\beta^{(b)}\) for the \(b\)-th OT problem in the batch. If not provided, we assume that \(b\) is the uniform distribution on \(M\) points for each problem in the batch, i.e. \(\beta_j^{(b)} = 1/M\) for all \(j\) and \(b\).

Other parameters are identical to those of solve(). They are applied uniformly to all problems in the batch.

Returns:

An object containing the optimal transport plans, the dual potentials and other related quantities for each problem in the batch as attributes.

Return type:

OTResultMatrix

Examples

from geomloss import ot
# Solve a batch of 2 balanced, 2x3 OT problems with entropic regularization:
solution = ot.solve_batch(
    C=[[[0., 1., 4.],
        [2., 1., 0.]],
       [[0., 2., 3.],
        [1., 0., 1.]]],
    a=[[2, 2],
       [1, 3]],
    b=[[1, 1, 2],
       [2, 1, 1]],
    reg=0.001,
    max_iter=1000,
)
print(solution.plan)
[[[1.    1.    0.   ]
  [0.    0.    2.   ]]

 [[1.005 0.    0.   ]
  [0.988 1.003 1.003]]]
print(f"{solution.value}")
[0.997 1.995]
class geomloss.ot.OTResultMatrix(*, a, b, C, potentials, array_properties, reg, reg_type, unbalanced, unbalanced_type)[source]

Stores the result of an optimal transport problem computed using an explicit cost matrix.

Users may access the optimal transport plan, the dual potentials and other related quantities as attributes of this class. Under the hood, these attributes are computed lazily and cached for efficiency. In the documentation below, \(B\) denotes the batch size while \(N\) and \(M\) denote the number of samples in the source and target measures, respectively.

property citation

Appropriate citation(s) for this result, in plain text and BibTex formats.

Since GeomLoss packages contributions from various authors, we provide a method that returns the appropriate citation(s) for the result at hand.

property density

Density \(P_{ij}\) of the transport plan with respect to the reference product measure \(\alpha \otimes \beta\).

Using the notations of the documentation of solve(), we have:

\[P_{ij} = \exp\left( \frac{f_i + g_j - C_{ij}}{\varepsilon} \right)~,\]

where \(f\) and \(g\) are the dual potentials of the optimal transport problem, \(C\) is the cost matrix and \(\varepsilon\) is the regularization strength.

Returns:

If this solution was computed with solve(), the density is returned as a (N,M) array. If this solution was computed with solve_batch(), the density is returned as a (B,N,M) array, where B is the batch size.

Return type:

(N,M) or (B,N,M) array-like >= 0

property density_operator

Linear operator associated to density.

Returns:

If this solution was computed with solve(), the returned operator can be applied to arrays of shape (M,...) to produce arrays of shape (N,...).

If this solution was computed with solve_batch(), the returned operator can be applied to arrays of shape (B,M,...) to produce arrays of shape (B,N,...).

Return type:

LinearOperator

property lazy_density

Density of the transport plan with respect to the reference measure, encoded as a symbolic KeOps LazyTensor.

property lazy_plan

Transport plan, encoded as a symbolic KeOps LazyTensor.

property marginal_a

First marginal \(\pi 1_M\) of the transport plan, with the same shape as the source weights a.

property marginal_b

Second marginal \(\pi^\intercal 1_N\) of the transport plan, with the same shape as the target weights b.

property plan

Optimal transport plan \(\pi_{ij}\).

Using the notations of the documentation of solve(), we have:

\[\pi_{ij} = \alpha_i \beta_j \cdot \exp\left( \frac{f_i + g_j - C_{ij}}{\varepsilon} \right)~,\]

where \(f\) and \(g\) are the dual potentials of the optimal transport problem, \(C\) is the cost matrix and \(\varepsilon\) is the regularization strength.

Returns:

If this solution was computed with solve(), the plan is returned as a (N,M) array. If this solution was computed with solve_batch(), the plan is returned as a (B,N,M) array, where B is the batch size.

Return type:

(N,M) or (B,N,M) array-like >= 0

property plan_operator

Linear operator associated to plan.

Example

import numpy as np
from geomloss import ot

# Solve a balanced, 2x3 OT problem with entropic regularization:
solution = ot.solve(
    C=[[0., 1., 4.],
       [2., 1., 0.]],
    a=[2, 2],
    b=[1, 1, 2],
    reg=0.001,
    max_iter=100,
)
print(solution.plan)
[[1. 1. 0.]
 [0. 0. 2.]]
print(solution.plan_operator @ np.array([-2., 1., 1.]))
[-1.  2.]
Returns:

If this solution was computed with solve(), the returned operator can be applied to arrays of shape (M,...) to produce arrays of shape (N,...).

If this solution was computed with solve_batch(), the returned operator can be applied to arrays of shape (B,M,...) to produce arrays of shape (B,N,...).

Return type:

LinearOperator

property potential_a

First dual potential \(f\), associated to the source measure \(\alpha\).

This real-valued Tensor has the same shape and numerical dtype as the Tensor of source weights a that was provided as input to the OT solver. It is also hosted on the same device (RAM, GPU memory…), using the same tensor computing library (NumPy, PyTorch…).

property potential_b

Second dual potential \(g\), associated to the target measure \(\beta\).

This real-valued Tensor has the same shape and numerical dtype as the Tensor of target weights b that was provided as input to the OT solver. It is also hosted on the same device (RAM, GPU memory…), using the same tensor computing library (NumPy, PyTorch…).

property value

Full transport cost, including possible regularization terms.

geomloss.ot.solve_sample(X_a, X_b, a=None, b=None, cost='sqeuclidean', debias=False, reg=None, unbalanced=None, unbalanced_type='KL', method='auto', max_iter=None, tol=None, blur=None, reach=None)[source]

Solves an optimal transport problem between point clouds.

Warning

The interface of this solver is still in development and may change in future releases. We welcome any feedback and suggestions for improvement.

Using the notations of the documentation of solve(), this function focuses on the case where the values of the cost matrix \(C_{ij} = C(x_i, y_j)\) are not provided as input, but are instead computed on the fly from the coordinates of the samples \(x_i\) (stored in the array X_a) and \(y_j\) (stored in the array X_b). This is the most common setting in geometric applications, where the cost is typically a power of the Euclidean distance between the points.

Parameters:
  • X_a ((N,D) array-like) – Coordinates of the \(N\) samples \(x_1, \dots, x_N\) of the source measure \(\alpha\).

  • X_b ((M,D) array-like) – Coordinates of the \(M\) samples \(y_1, \dots, y_M\) of the target measure \(\beta\).

  • cost (str or callable, default: "sqeuclidean") –

    Cost function, either specified as a string (e.g. "sqeuclidean") or as a Python callable that takes as input two arrays of coordinates and returns the cost matrix.

    Currently, we only support "sqeuclidean" as a string shortcut for the squared Euclidean distance.

  • debias (bool, default: False) – Whether to compute the debiased Sinkhorn divergence, which returns an unbiased estimate of the unregularized OT cost without shrinking artifacts (the so-called “entropic bias”). This is desirable when the value of the optimal transport problem is used as a loss function.

  • blur (float > 0, default: None) – Redundant parameter that specifies the regularization strength as \(\texttt{reg} = \varepsilon = 2 * \texttt{blur}^2\), when the cost is the squared Euclidean distance. This is a more intuitive parameter for geometric applications, since it corresponds to the “blurring radius” \(\sigma\) of the kernel \(k(x,y) = e^{-\|x-y\|^2 / 2 \sigma^2} = e^{-\|x-y\|^2 / \varepsilon}\). This parameter should not be used together with reg, which is a more general regularization parameter that can be used with any cost and any regularization type.

  • reach (float > 0, default: None) – Redundant parameter that specifies the unbalanced OT penalty strength as \(\texttt{unbalanced} = \rho = 2 * \texttt{reach}^2\), when the cost is the squared Euclidean distance.

Other parameters are identical to those of solve() and control the regularization strength, the unbalanced OT penalty type and strength, the optimization method and parameters, etc. See the documentation of solve() for more details.

Examples

from geomloss import ot

solution = ot.solve_sample(
    X_a=[[0, 0], [0, 2]],
    X_b=[[2, 1], [2, 2]],
    reg=0.001,
    max_iter=100,
)
print(solution.plan)
[[0.5 0. ]
 [0.  0.5]]
print(f"{solution.value:.3f}")
4.501
class geomloss.ot.OTResultSample(*, X_a, X_b, a, b, C, cost, reg, reg_type, unbalanced, unbalanced_type, debias, potentials, array_properties)[source]

Stores the result of an optimal transport problem computed using point positions.

Users may access the optimal transport plan, the dual potentials and other related quantities as attributes of this class. Under the hood, these attributes are computed lazily and cached for efficiency. In the documentation below, \(N\) and \(M\) denote the number of samples in the source and target measures, respectively.

property a_to_b

Displacement vectors from the first to the second measure.

property b_to_a

Displacement vectors from the second to the first measure.

property citation

Appropriate citation(s) for this result, in plain text and BibTex formats.

Since GeomLoss packages contributions from various authors, we provide a method that returns the appropriate citation(s) for the result at hand.

property density

Density \(P_{ij}\) of the transport plan with respect to the reference product measure \(\alpha \otimes \beta\).

Using the notations of the documentation of solve(), we have:

\[P_{ij} = \exp\left( \frac{f_i + g_j - C(x_i, y_j)}{\varepsilon} \right)~,\]

where \(f\) and \(g\) are the dual potentials of the optimal transport problem, \(C\) is the cost function and \(\varepsilon\) is the regularization strength.

Returns:

If this solution was computed with solve_sample(), the density is returned as a (N,M) array.

Return type:

(N,M) array-like >= 0

property density_operator

Density of the transport plan, encoded as a LinearOperator.

property lazy_density

Density of the transport plan, encoded as a symbolic KeOps LazyTensor.

property lazy_plan

Transport plan, encoded as a symbolic KeOps LazyTensor.

property marginal_a

First marginal \(\pi 1_M\) of the transport plan, with the same shape as the source weights a.

property marginal_b

Second marginal \(\pi^\intercal 1_N\) of the transport plan, with the same shape as the target weights b.

property plan

Transport plan, encoded as a dense array.

property plan_operator

Transport plan, encoded as a linear operator.

property potential_a

First dual potential \(f\), associated to the source measure \(\alpha\).

This real-valued Tensor has the same shape and numerical dtype as the Tensor of source weights a that was provided as input to the OT solver. It is also hosted on the same device (RAM, GPU memory…), using the same tensor computing library (NumPy, PyTorch…).

property potential_aa

Dual potential associated to the self-interaction of the source measure \(\alpha\).

This potential is only defined when using a debiased Sinkhorn solver. This real-valued Tensor has the same shape and numerical dtype as the Tensor of source weights a that was provided as input to the OT solver. It is also hosted on the same device (RAM, GPU memory…), using the same tensor computing library (NumPy, PyTorch…).

property potential_b

Second dual potential \(g\), associated to the target measure \(\beta\).

This real-valued Tensor has the same shape and numerical dtype as the Tensor of target weights b that was provided as input to the OT solver. It is also hosted on the same device (RAM, GPU memory…), using the same tensor computing library (NumPy, PyTorch…).

property potential_bb

Dual potential associated to the self-interaction of the target measure \(\beta\).

This potential is only defined when using a debiased Sinkhorn solver. This real-valued Tensor has the same shape and numerical dtype as the Tensor of target weights b that was provided as input to the OT solver. It is also hosted on the same device (RAM, GPU memory…), using the same tensor computing library (NumPy, PyTorch…).

property value

Full transport cost, including possible regularization terms.

class geomloss.ot.LinearOperator(*, matmat, rmatmat, input_shape, output_shape)[source]

Linear operator that can be applied to arrays, without being explicitly instantiated as a matrix.

__matmul__(x)[source]

Applies the linear operator to an array x.

property T

Alias for transpose() .

classmethod from_dense(dense_matrix, *, input_shape, output_shape)[source]

Returns a LinearOperator that behaves like the given dense matrix.

classmethod from_lazy_tensor(lazy_tensor, *, input_shape, output_shape)[source]

Returns a LinearOperator that behaves like the given KeOps LazyTensor.

rescale(*, input_scaling, output_scaling)[source]

Returns a new LinearOperator that behaves like the original one, but with rescaled inputs and outputs.

property shape

For compatibility with e.g. SciPy’s LinearOperator class.

transpose()[source]

Returns the transposed linear operator.