class ott.solvers.linear.univariate.UnivariateSolver(num_subsamples=None, quantiles=None)[source]#

Univariate solver to compute 1D OT distance over slices of data.

Computes 1-Dimensional optimal transport distance between two $d$-dimensional point clouds. The total distance is the sum of univariate Wasserstein distances on the $d$ slices of data: given two weighted point-clouds, stored as [n, d] and [m, d] in a LinearProblem object, with respective weights a and b, the solver computes d OT distances between each of these [n, 1] and [m, 1] slices. The distance is computed using the analytical formula by default, which involves sorting each of the slices independently. The optimal transport matrices are also outputted when possible (described in sparse form, i.e. pairs of indices and mass transferred between those indices).

When weights a and b are uniform, and n=m, the computation only involves comparing sorted entries per slice, and d assignments are given.

The user may also supply a num_subsamples parameter to extract as many points from the original point cloud, sampled with probability masses a and b. This then simply applied the method above to the subsamples, to output d costs, but assignments are not provided.

When the problem is not uniform or not of equal size, the method defaults to an inversion of the CDF, and outputs both costs and transport matrix in sparse form.

When a quantiles argument is passed, either specifying explicit quantiles or a grid of quantiles, the distance is evaluated by comparing the quantiles of the two point clouds on each slice. The OT costs are returned but assignments are not provided.

  • num_subsamples (Optional[int]) – Option to reduce the size of inputs by doing random subsampling, taken into account marginal probabilities.

  • quantiles (Union[int, Array, None]) – When a vector or a number of quantiles is passed, the distance is computed by evaluating the cost function on the sectional (one for each dimension) quantiles of the two point cloud distributions described in the problem.




Number of quantiles used to evaluate OT cost.


Quantiles' values used to evaluate OT cost.