deblais
Exact optimal transport between point clouds
Loading...
Searching...
No Matches
deblais Namespace Reference

Public interface of the library. More...

Classes

struct  Certificate
 Measured optimality of a plan, as returned by certify(). More...
struct  Options
 Options of solve(). More...
struct  Stats
 Counters and timings of a solve, returned in Plan::stats. More...
struct  Cloud
 A weighted point cloud: a non-owning view of the data of the caller. More...
struct  Plan
 An optimal transport plan and its dual certificate. More...
struct  Recipe
 What the automatic mode decides for a problem, as returned by recipe(). More...
struct  AutoThresholds
 Sizes at which the automatic mode changes method. More...
struct  Trial
 One timed configuration of tune(). More...
struct  Tuning
 Result of tune(). More...
struct  TuneOptions
 Bounds of the search of tune(). More...

Enumerations

enum class  Method {
  automatic , line , simplex , multiscale ,
  decomposition
}
 Algorithm used by solve(). More...
enum class  Flows { automatic , real , integer }
 Arithmetic of the flows inside the solver. More...
enum class  Status { optimal , stalled }
 Outcome of a solve. More...

Functions

template<int D>
Certificate certify (const Cloud &source, const Cloud &target, const Plan &plan, bool all_pairs=true)
 Certifies a plan against the problem it is meant to solve.
Recipe recipe (int dim, std::size_t n1, std::size_t n2, const Options &options=Options())
 The automatic mode: method and main parameters chosen for a problem.
template<int D>
Plan solve (const Cloud &source, const Cloud &target, const Options &options=Options())
 Solves the optimal transport problem between two weighted point clouds for the cost \(|x - y|^p\) (Options::p, 2 by default).
Plan solve (int dim, const Cloud &source, const Cloud &target, const Options &options=Options())
 Solves a problem whose dimension is known at run time.
Plan solve (int dim, const std::vector< double > &x, const std::vector< double > &y, const Options &options=Options())
 Solves between the uniform probability measures of two clouds stored point after point.
Plan solve (int dim, const std::vector< double > &x, const std::vector< double > &a, const std::vector< double > &y, const std::vector< double > &b, const Options &options=Options())
 Solves between two weighted clouds stored point after point.
template<std::size_t D>
Plan solve (const std::vector< std::array< double, D > > &x, const std::vector< std::array< double, D > > &y, const Options &options=Options())
 Solves between the uniform probability measures of two vectors of points.
template<std::size_t D>
Plan solve (const std::vector< std::array< double, D > > &x, const std::vector< double > &a, const std::vector< std::array< double, D > > &y, const std::vector< double > &b, const Options &options=Options())
 Solves between two weighted vectors of points.
template<int D>
Tuning tune (const Cloud &source, const Cloud &target, const Options &base=Options(), const TuneOptions &bounds=TuneOptions())
 Finds the fastest options for two clouds on this machine.
Tuning tune (int dim, const Cloud &source, const Cloud &target, const Options &base=Options(), const TuneOptions &bounds=TuneOptions())
 tune() for a dimension known at run time.

Variables

constexpr const char * version = DEBLAIS_VERSION_STRING
 Version of the library, "major.minor.patch".

Detailed Description

Public interface of the library.

Enumeration Type Documentation

◆ Method

enum class deblais::Method
strong

Algorithm used by solve().

Every method returns an exact optimal plan: they only differ in speed.

See also
recipe() for the choice made by Method::automatic.
Enumerator
automatic 

Chosen from the dimension and the sizes of the clouds, see recipe().

line 

Closed form on the line (monotone rearrangement). Dimension 1 only.

simplex 

Network simplex with column generation, started from scratch.

multiscale 

Simplex warm started by a multiscale solve of clustered problems.

decomposition 

Multiscale start whose levels are improved by parallel sweeps of a domain decomposition before the final simplex.

The fastest method on large problems, and the one that benefits the most from several threads.

◆ Flows

enum class deblais::Flows
strong

Arithmetic of the flows inside the solver.

The masses of the returned Plan are always doubles, in the units of the caller.

Enumerator
automatic 

Integers when the masses allow it (uniform or integer masses), reals otherwise.

real 

Double precision flows.

integer 

Integer flows: exact, without rounding tolerances.

The masses must be integers, or uniform on each side; solve() throws std::invalid_argument otherwise.

◆ Status

enum class deblais::Status
strong

Outcome of a solve.

Enumerator
optimal 

The plan is optimal.

The last pricing pass over all the arcs found no arc with a negative reduced cost.

stalled 

The plan is feasible, and optimal up to rounding.

The last pricing pass found arcs that violate optimality by less than Stats::max_violation, which the simplex cannot use in double precision.

Function Documentation

◆ certify()

template<int D>
Certificate deblais::certify ( const Cloud & source,
const Cloud & target,
const Plan & plan,
bool all_pairs = true )

Certifies a plan against the problem it is meant to solve.

The check uses nothing of the solver: it recomputes the marginals of the plan, its cost, the value of the dual and, optionally, the dual constraint on every pair of points.

Template Parameters
DDimension of the points.
Parameters
sourceSource cloud given to solve().
targetTarget cloud given to solve().
planPlan to check. It must carry its potentials.
all_pairsAlso check the dual constraint on the n1 * n2 pairs. This is the costly part (quadratic, run in parallel): leave it out on large problems, where solve() has already checked every pair with pruning.
Returns
The measured errors.
Exceptions
std::invalid_argumentif the plan has no potentials.

◆ recipe()

Recipe deblais::recipe ( int dim,
std::size_t n1,
std::size_t n2,
const Options & options = Options() )
inline

The automatic mode: method and main parameters chosen for a problem.

  • dimension 1: closed form on the line, whatever the size, for \(p \ge 1\) (below, the cost is not convex: the rule of dimension 2);
  • fewer than AutoThresholds::decompositionFrom(dim) points in both clouds (500 in dimension 2, 2000 above): plain simplex;
  • otherwise: multiscale start and domain decomposition, 2 sweeps per level, with a coarsest level of AutoThresholds::minSize() points (from 100 to 3000, a sixth of the points at most).

The rule was measured for the squared Euclidean cost (Options::p = 2). For other exponents tune() is the better guide. Explicit choices made in options are kept. Two more decisions are taken inside solve() from the masses: integer flows when they are uniform or integers (Options::flows), and auctions on the levels of the multiscale start for assignment problems (Options::auction).

Parameters
dimDimension of the points.
n1Number of source points.
n2Number of target points.
optionsOptions of the solve.
Returns
The method and the parameters that solve() will use.

◆ solve() [1/6]

template<int D>
Plan deblais::solve ( const Cloud & source,
const Cloud & target,
const Options & options = Options() )

Solves the optimal transport problem between two weighted point clouds for the cost \(|x - y|^p\) (Options::p, 2 by default).

The masses must be non negative, with equal totals up to Options::mass_tolerance. A cloud without masses carries the uniform probability measure. Points of zero mass are accepted: they take no part in the plan and still receive a potential.

Template Parameters
DDimension of the points, at least 1.
Parameters
sourceSource cloud (points \(x_i\), masses \(a_i\)).
targetTarget cloud (points \(y_j\), masses \(b_j\)).
optionsOptions of the solve. The default is the automatic mode.
Returns
The optimal plan, its cost and its potentials.
Exceptions
std::invalid_argumentif a cloud is empty, a coordinate or a mass is not finite, a mass is negative, the total masses differ, Options::p is not positive, or the options do not apply to the problem.
Example
std::vector<double> x = ..., y = ...; // interleaved coordinates, dimension 3
deblais::Plan plan = deblais::solve<3>({x.data(), x.size() / 3}, {y.data(), y.size() / 3});
Plan solve(const Cloud &source, const Cloud &target, const Options &options=Options())
Solves the optimal transport problem between two weighted point clouds for the cost (Options::p,...
Definition solve.hpp:486
An optimal transport plan and its dual certificate.
Definition plan.hpp:66

◆ solve() [2/6]

Plan deblais::solve ( int dim,
const Cloud & source,
const Cloud & target,
const Options & options = Options() )
inline

Solves a problem whose dimension is known at run time.

Parameters
dimDimension of the points, from 1 to DEBLAIS_MAX_DIM.
sourceSource cloud.
targetTarget cloud.
optionsOptions of the solve.
Returns
The optimal plan, its cost and its potentials.
Exceptions
std::invalid_argumenton invalid input, or if dim is out of range.

◆ solve() [3/6]

Plan deblais::solve ( int dim,
const std::vector< double > & x,
const std::vector< double > & y,
const Options & options = Options() )
inline

Solves between the uniform probability measures of two clouds stored point after point.

Parameters
dimDimension of the points, from 1 to DEBLAIS_MAX_DIM.
xSource points: n1 * dim coordinates.
yTarget points: n2 * dim coordinates.
optionsOptions of the solve.
Returns
The optimal plan, its cost and its potentials.
Exceptions
std::invalid_argumenton invalid input, or if a size is not a multiple of dim.

◆ solve() [4/6]

Plan deblais::solve ( int dim,
const std::vector< double > & x,
const std::vector< double > & a,
const std::vector< double > & y,
const std::vector< double > & b,
const Options & options = Options() )
inline

Solves between two weighted clouds stored point after point.

Parameters
dimDimension of the points, from 1 to DEBLAIS_MAX_DIM.
xSource points: n1 * dim coordinates.
aMasses of the n1 source points.
yTarget points: n2 * dim coordinates.
bMasses of the n2 target points.
optionsOptions of the solve.
Returns
The optimal plan, its cost and its potentials.
Exceptions
std::invalid_argumenton invalid input, or if the sizes do not match.

◆ solve() [5/6]

template<std::size_t D>
Plan deblais::solve ( const std::vector< std::array< double, D > > & x,
const std::vector< std::array< double, D > > & y,
const Options & options = Options() )

Solves between the uniform probability measures of two vectors of points.

Template Parameters
DDimension of the points.
Parameters
xSource points.
yTarget points.
optionsOptions of the solve.
Returns
The optimal plan, its cost and its potentials.
Exceptions
std::invalid_argumenton invalid input.

◆ solve() [6/6]

template<std::size_t D>
Plan deblais::solve ( const std::vector< std::array< double, D > > & x,
const std::vector< double > & a,
const std::vector< std::array< double, D > > & y,
const std::vector< double > & b,
const Options & options = Options() )

Solves between two weighted vectors of points.

Template Parameters
DDimension of the points.
Parameters
xSource points.
aMasses of the source points, one per point.
yTarget points.
bMasses of the target points, one per point.
optionsOptions of the solve.
Returns
The optimal plan, its cost and its potentials.
Exceptions
std::invalid_argumenton invalid input, or if the sizes do not match.

◆ tune() [1/2]

template<int D>
Tuning deblais::tune ( const Cloud & source,
const Cloud & target,
const Options & base = Options(),
const TuneOptions & bounds = TuneOptions() )

Finds the fastest options for two clouds on this machine.

recipe() predicts the options of the automatic mode from the dimension and the sizes alone. tune() measures instead: it solves the problem with the automatic mode, then improves one choice at a time, keeping a change when it makes the solve faster:

  1. the method (simplex from scratch up to 20 000 points, multiscale start, domain decomposition);
  2. the number of threads, halved while the time does not grow, doubled when it gets faster;
  3. the size of the coarsest level of the multiscale start (Options::min_size), from 100 to 30 000 points;
  4. the auctions of assignment problems;
  5. the sweeps and the cell size of the domain decomposition.

Steps 2 to 5 are repeated while one of them changes something, three times at most: the fields interact. Configurations already timed are not timed again.

Every configuration is an exact solve, so the search costs 10 to 25 configurations. It pays off when many problems of the same size and shape follow, as in a training loop. Short solves are repeated and the fastest time is kept.

Template Parameters
DDimension of the points.
Parameters
sourceSource cloud.
targetTarget cloud.
baseStarting options. Choices made explicitly in it are kept (a method other than Method::automatic, a positive number of threads as the maximum); the flows, the potentials and the mass tolerance are copied to the result.
boundsBounds of the search.
Returns
The fastest options, their time, the plan and every trial.
Exceptions
std::invalid_argumenton invalid input, as solve().

◆ tune() [2/2]

Tuning deblais::tune ( int dim,
const Cloud & source,
const Cloud & target,
const Options & base = Options(),
const TuneOptions & bounds = TuneOptions() )
inline

tune() for a dimension known at run time.

Parameters
dimDimension of the points, from 1 to DEBLAIS_MAX_DIM.
sourceSource cloud.
targetTarget cloud.
baseStarting options.
boundsBounds of the search.
Returns
The fastest options, their time, the plan and every trial.