Repository navigation
Expand file tree
/
Copy pathot.bsp.html
More file actions
278 lines (238 loc) · 18.3 KB
/
Copy pathot.bsp.html
File metadata and controls
278 lines (238 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ot.bsp — POT Python Optimal Transport 0.9.8.dev documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=9edc463e" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery.css?v=c83e6b79" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery-binder.css?v=f4aeca0c" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery-dataframe.css?v=2082cf3c" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery-rendered-html.css?v=1277b6f3" />
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=dd0b68c4"></script>
<script src="../_static/doctools.js?v=fd6eb6e6"></script>
<script src="../_static/sphinx_highlight.js?v=6ffebe34"></script>
<script src="../_static/sg-tags.js?v=d80f6fa4"></script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="ot.coot" href="ot.coot.html" />
<link rel="prev" title="ot.bregman" href="ot.bregman.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home">
POT Python Optimal Transport
<img src="../_static/logo_dark.svg" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">POT: Python Optimal Transport</a></li>
<li class="toctree-l1"><a class="reference internal" href="../auto_examples/plot_quickstart_guide.html">Quickstart Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../auto_examples/index.html">Examples gallery</a></li>
<li class="toctree-l1"><a class="reference internal" href="../user_guide.html">User guide</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../all.html">API and modules</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="ot.backend.html">ot.backend</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.batch.html">ot.batch</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.bregman.html">ot.bregman</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">ot.bsp</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#ot.bsp.compute_bspot_bijection"><code class="docutils literal notranslate"><span class="pre">compute_bspot_bijection()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#ot.bsp.merge_bijections"><code class="docutils literal notranslate"><span class="pre">merge_bijections()</span></code></a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="ot.coot.html">ot.coot</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.da.html">ot.da</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.datasets.html">ot.datasets</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.dr.html">ot.dr</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.factored.html">ot.factored</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.gaussian.html">ot.gaussian</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.gmm.html">ot.gmm</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.gnn.html">ot.gnn</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.gromov.html">ot.gromov</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.lowrank.html">ot.lowrank</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.lp.html">ot.lp</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.mapping.html">ot.mapping</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.optim.html">ot.optim</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.partial.html">ot.partial</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.plot.html">ot.plot</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.regpath.html">ot.regpath</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.sliced.html">ot.sliced</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.sgot.html">ot.sgot</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.smooth.html">ot.smooth</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.stochastic.html">ot.stochastic</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.unbalanced.html">ot.unbalanced</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.utils.html">ot.utils</a></li>
<li class="toctree-l2"><a class="reference internal" href="ot.weak.html">ot.weak</a></li>
<li class="toctree-l2"><a class="reference internal" href="../all.html#module-ot">Main <code class="xref py py-mod docutils literal notranslate"><span class="pre">ot</span></code> functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../releases.html">Releases</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributors.html">Contributors</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">Contributing to POT</a></li>
<li class="toctree-l1"><a class="reference internal" href="../code_of_conduct.html">Code of conduct</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">POT Python Optimal Transport</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../all.html">API and modules</a></li>
<li class="breadcrumb-item active">ot.bsp</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/gen_modules/ot.bsp.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="module-ot.bsp">
<span id="ot-bsp"></span><h1>ot.bsp<a class="headerlink" href="#module-ot.bsp" title="Link to this heading"></a></h1>
<p>Efficient combinatorial optimization for low transport cost bijections based on Binary Space Partitioning trees (BSP-OT).</p>
<dl class="py function">
<dt class="sig sig-object py" id="ot.bsp.compute_bspot_bijection">
<span class="sig-prename descclassname"><span class="pre">ot.bsp.</span></span><span class="sig-name descname"><span class="pre">compute_bspot_bijection</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n_plans</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">64</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">initial_perm</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gaussian_slicing</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'auto'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/bsp/bsp_ot.html#compute_bspot_bijection"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.bsp.compute_bspot_bijection" title="Link to this definition"></a></dt>
<dd><p>This solver provides a good and fast approximation of the combinatorial problem of finding
a bijection between two point clouds that minimizes the transport cost:</p>
<div class="math notranslate nohighlight">
\[\min_{\sigma \in S_n} \sum_{i=1}^n \|X_i - Y_{\sigma(i)}\|_p^p\]</div>
<p>To do so, it generates <span class="math notranslate nohighlight">\(n_{plans}\)</span> random bijective BSP matchings, merges them together to obtain a bijection of low transport cost.
Log-linear complexity in the number of points. Algorithm 2 & 3 from [84].</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>There is no guarantee on the quality of the returned bijection, but the method is highly scalable on the CPU.
Worst cases are obtained between point clouds that are very similar (e.g. two samples from the same distribution),
where the solver can get stuck in local minima, but works well when the point clouds are very different.
The method also works best for the standard squared euclidean cost (p=2), as this cost enables
efficient BSP construction heuristic (with a cubic dependence on the dimension, this feature is disabled
for dimensions larger than 64).</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples</em><em>, </em><em>dimension</em><em>)</em>)</p></li>
<li><p><strong>Y</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples</em><em>, </em><em>dimension</em><em>)</em>)</p></li>
<li><p><strong>n_plans</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a>) – The number of BSP Matchings used to compute the final bijection.</p></li>
<li><p><strong>p</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a><em>, </em><em>optional</em>) – The power of the ground metric (default 2 for squared euclidean, -1 for infinity norm).</p></li>
<li><p><strong>initial_perm</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples</em><em>,</em><em>)</em><em>, </em><em>optional</em>) – Bijection to use for initializing merging (optional).</p></li>
<li><p><strong>gaussian_slicing</strong> (<em>"auto"</em><em> or </em><a class="reference external" href="https://docs.python.org/3/builtins/functions.html#bool" title="(in Python v3.15)"><em>bool</em></a><em>, </em><em>optional</em>) – If true then uses the Gaussian slicing heuristic to improve matching quality.
Comes with a cubic complexity with dimension.
If ‘auto’, then the heuristic is used for dimensions smaller than 64, and disabled for larger dimensions.</p></li>
<li><p><strong>seed</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a><em>, </em><em>optional</em>) – Random seed for reproducibility (default 0).</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>cost</strong> (<em>float</em>) – The transport cost of the final bijection.</p></li>
<li><p><strong>perm</strong> (<em>array-like, shape (n_samples,)</em>) – The final bijection, stored as a permutation (e.g. a list of numbers) such that X[i] is assigned to Y[perm[i]].</p></li>
<li><p><strong>perms</strong> (<em>array-like, shape (n_plans,n_samples)</em>) – The intermediary bijections used to compute the final one.</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="ot.bsp.merge_bijections">
<span class="sig-prename descclassname"><span class="pre">ot.bsp.</span></span><span class="sig-name descname"><span class="pre">merge_bijections</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Y</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">perms</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">p</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/bsp/bsp_ot.html#merge_bijections"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.bsp.merge_bijections" title="Link to this definition"></a></dt>
<dd><p>Merge several bijections between two point clouds to obtain a new one with low transport cost.
The new bijection is guaranteed to have a transport cost no greater than the cost of any of the input bijections.
Based on simple local/global swapping strategy, with a linear complexity in the number of points.
Algorithm 3 from [84].</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples</em><em>, </em><em>dimension</em><em>)</em>)</p></li>
<li><p><strong>Y</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples</em><em>, </em><em>dimension</em><em>)</em>)</p></li>
<li><p><strong>perms</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_plans</em><em>,</em><em>n_samples</em><em>)</em>) – The bijections to merge, stored as permutations (e.g. a list of numbers)</p></li>
<li><p><strong>p</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a><em>, </em><em>optional</em>) – The power of the ground metric (default 2 for squared euclidean).
If p is -1, the infinity norm is used.</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><ul class="simple">
<li><p><strong>cost</strong> (<em>float</em>) – The transport cost of the merged bijection.</p></li>
<li><p><strong>perm</strong> (<em>array-like, shape (n_samples,)</em>) – The merged bijection, stored as a permutation (e.g. a list of numbers) such that X[i] is assigned to Y[perm[i]].</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="ot.bregman.html" class="btn btn-neutral float-left" title="ot.bregman" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="ot.coot.html" class="btn btn-neutral float-right" title="ot.coot" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>© Copyright 2016-2026, POT Contributors.</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" data-toggle="rst-versions" role="note"
aria-label="versions">
<!-- add shift_up to the class for force viewing ,
data-toggle="rst-current-version" -->
<span class="rst-current-version" style="margin-bottom:1mm;">
<span class="fa fa-book"> Python Optimal Transport</span> 0.9.8.dev
<hr style="margin-bottom:1.5mm;margin-top:5mm;">
<!-- versions
<span class="fa fa-caret-down"></span>-->
<span class="rst-current-version" style="display: inline-block;padding:
0px;color:#fcfcfcab;float:left;font-size: 100%;">
Versions:
<a href="https://pythonot.github.io/"
style="padding: 3px;color:#fcfcfc;font-size: 100%;">Release</a>
<a href="https://pythonot.github.io/master"
style="padding: 3px;color:#fcfcfc;font-size: 100%;">Development</a>
<a href="https://github.com/PythonOT/POT"
style="padding: 3px;color:#fcfcfc;font-size: 100%;">Code</a>
</span>
</span>
<!--
<div class="rst-other-versions">
<div class="injected">
<dl>
<dt>Versions</dt>
<dd><a href="https://pythonot.github.io/">Release</a></dd>
<dd><a href="https://pythonot.github.io/master">Development</a></dd>
<dt><a href="https://github.com/PythonOT/POT">Code on Github</a></dt>
</dl>
<hr>
</div>
</div>-->
</div><script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>