|
deblais
Exact optimal transport between point clouds
|
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". | |
Public interface of the library.
|
strong |
Algorithm used by solve().
Every method returns an exact optimal plan: they only differ in speed.
| 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. |
|
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. |
|
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. |
| 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.
| D | Dimension of the points. |
| source | Source cloud given to solve(). |
| target | Target cloud given to solve(). |
| plan | Plan to check. It must carry its potentials. |
| all_pairs | Also 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. |
| std::invalid_argument | if the plan has no potentials. |
|
inline |
The automatic mode: method and main parameters chosen for a problem.
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).
| dim | Dimension of the points. |
| n1 | Number of source points. |
| n2 | Number of target points. |
| options | Options of the solve. |
| 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.
| D | Dimension of the points, at least 1. |
| source | Source cloud (points \(x_i\), masses \(a_i\)). |
| target | Target cloud (points \(y_j\), masses \(b_j\)). |
| options | Options of the solve. The default is the automatic mode. |
| std::invalid_argument | if 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. |
|
inline |
Solves a problem whose dimension is known at run time.
| dim | Dimension of the points, from 1 to DEBLAIS_MAX_DIM. |
| source | Source cloud. |
| target | Target cloud. |
| options | Options of the solve. |
| std::invalid_argument | on invalid input, or if dim is out of range. |
|
inline |
Solves between the uniform probability measures of two clouds stored point after point.
| dim | Dimension of the points, from 1 to DEBLAIS_MAX_DIM. |
| x | Source points: n1 * dim coordinates. |
| y | Target points: n2 * dim coordinates. |
| options | Options of the solve. |
| std::invalid_argument | on invalid input, or if a size is not a multiple of dim. |
|
inline |
Solves between two weighted clouds stored point after point.
| dim | Dimension of the points, from 1 to DEBLAIS_MAX_DIM. |
| x | Source points: n1 * dim coordinates. |
| a | Masses of the n1 source points. |
| y | Target points: n2 * dim coordinates. |
| b | Masses of the n2 target points. |
| options | Options of the solve. |
| std::invalid_argument | on invalid input, or if the sizes do not match. |
| 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.
| D | Dimension of the points. |
| x | Source points. |
| y | Target points. |
| options | Options of the solve. |
| std::invalid_argument | on invalid input. |
| 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.
| D | Dimension of the points. |
| x | Source points. |
| a | Masses of the source points, one per point. |
| y | Target points. |
| b | Masses of the target points, one per point. |
| options | Options of the solve. |
| std::invalid_argument | on invalid input, or if the sizes do not match. |
| 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:
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.
| D | Dimension of the points. |
| source | Source cloud. |
| target | Target cloud. |
| base | Starting 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. |
| bounds | Bounds of the search. |
| std::invalid_argument | on invalid input, as solve(). |
|
inline |
tune() for a dimension known at run time.
| dim | Dimension of the points, from 1 to DEBLAIS_MAX_DIM. |
| source | Source cloud. |
| target | Target cloud. |
| base | Starting options. |
| bounds | Bounds of the search. |