Repository navigation
Expand file tree
/
Copy pathot.lowrank.html
More file actions
558 lines (512 loc) · 59.8 KB
/
Copy pathot.lowrank.html
File metadata and controls
558 lines (512 loc) · 59.8 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
<!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.lowrank — POT Python Optimal Transport 0.9.7 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=fd6457a4" />
<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=f2328ca0"></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.lp" href="ot.lp.html" />
<link rel="prev" title="ot.gromov" href="ot.gromov.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"><a class="reference internal" href="ot.bsp.html">ot.bsp</a></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 current"><a class="current reference internal" href="#">ot.lowrank</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#functions">Functions</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#ot.lowrank.compute_lr_sqeuclidean_matrix"><code class="docutils literal notranslate"><span class="pre">compute_lr_sqeuclidean_matrix()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#ot.lowrank.kernel_nystroem"><code class="docutils literal notranslate"><span class="pre">kernel_nystroem()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#examples-using-ot-lowrank-kernel-nystroem">Examples using <code class="docutils literal notranslate"><span class="pre">ot.lowrank.kernel_nystroem</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#examples-using-ot-lowrank-sinkhorn-low-rank-kernel">Examples using <code class="docutils literal notranslate"><span class="pre">ot.lowrank.sinkhorn_low_rank_kernel</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#id0"><code class="docutils literal notranslate"><span class="pre">compute_lr_sqeuclidean_matrix()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id4"><code class="docutils literal notranslate"><span class="pre">kernel_nystroem()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id5"><code class="docutils literal notranslate"><span class="pre">lowrank_sinkhorn()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id7"><code class="docutils literal notranslate"><span class="pre">sinkhorn_low_rank_kernel()</span></code></a></li>
</ul>
</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.lowrank</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/gen_modules/ot.lowrank.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.lowrank">
<span id="ot-lowrank"></span><h1>ot.lowrank<a class="headerlink" href="#module-ot.lowrank" title="Link to this heading"></a></h1>
<p>Low rank OT solvers</p>
<section id="functions">
<h2>Functions<a class="headerlink" href="#functions" title="Link to this heading"></a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="ot.lowrank.compute_lr_sqeuclidean_matrix">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">compute_lr_sqeuclidean_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X_s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">X_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rescale_cost</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#compute_lr_sqeuclidean_matrix"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.lowrank.compute_lr_sqeuclidean_matrix" title="Link to this definition"></a></dt>
<dd><p>Compute the low rank decomposition of a squared euclidean distance matrix.
This function won’t work for other distance metrics.</p>
<p>See “Section 3.5, proposition 1”</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_s</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim</em><em>)</em>) – samples in the source domain</p></li>
<li><p><strong>X_t</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>rescale_cost</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a>) – Rescale the low rank factorization of the sqeuclidean cost matrix</p></li>
<li><p><strong>nx</strong> (<em>default None</em>) – POT backend</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>M1</strong> (<em>array-like, shape (n_samples_a, dim+2)</em>) – First low rank decomposition of the distance matrix</p></li>
<li><p><strong>M2</strong> (<em>array-like, shape (n_samples_b, dim+2)</em>) – Second low rank decomposition of the distance matrix</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id1" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>65<span class="fn-bracket">]</span></span>
<p>Scetbon, M., Cuturi, M., & Peyré, G. (2021).
“Low-rank Sinkhorn factorization”. In International Conference on Machine Learning.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.lowrank.kernel_nystroem">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">kernel_nystroem</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X_s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">X_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">anchors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">50</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">random_state</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#kernel_nystroem"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.lowrank.kernel_nystroem" title="Link to this definition"></a></dt>
<dd><p>Compute left and right factors corresponding to the Nystroem method on the Gaussian kernel <span class="math notranslate nohighlight">\(K(x^s_i, x^t_j) = \exp(-\|x^s_i-x^t_j\|^2/2\sigma^2)\)</span>.
The Nystroem approximation is computed by sampling <span class="math notranslate nohighlight">\(\min(n, \lceil(c / 2))\rceil)\)</span> components in each distribution,
where <span class="math notranslate nohighlight">\(n\)</span> is the number of samples in the distribution and <span class="math notranslate nohighlight">\(c\)</span> the total number of anchor points.</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_s</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim</em><em>)</em>) – samples in the source domain</p></li>
<li><p><strong>X_t</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>anchors</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional</em>) – The total number of anchors sampled for the Nystroem approximation (anchors/2 in each distribution), default 50.</p></li>
<li><p><strong>sigma</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional</em>) – The standard deviation parameter for the Gaussian kernel.</p></li>
<li><p><strong>random_state</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional</em>) – The random state for sampling the components in each distribution.</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>left_factor</strong> (<em>array-like, shape (n_samples_a, dim_r)</em>) – Left factor of Nystroem</p></li>
<li><p><strong>right_factor</strong> (<em>array-like, shape (n_samples_b, dim_r)</em>) – Right factor of Nystroem</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
<section id="examples-using-ot-lowrank-kernel-nystroem">
<h3>Examples using <code class="docutils literal notranslate"><span class="pre">ot.lowrank.kernel_nystroem</span></code><a class="headerlink" href="#examples-using-ot-lowrank-kernel-nystroem" title="Link to this heading"></a></h3>
<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="Shows how to use Nyström kernel approximation for approximating the Sinkhorn algorithm in linear time."><img alt="" src="../_images/sphx_glr_plot_nystroem_approximation_thumb.png" />
<p><a class="reference internal" href="../auto_examples/lowrank/plot_nystroem_approximation.html"><span class="doc">Nyström approximation for OT</span></a></p>
<div class="sphx-glr-thumbnail-title">Nyström approximation for OT</div>
</div></div><div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.lowrank.lowrank_sinkhorn">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">lowrank_sinkhorn</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X_s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">X_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</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">b</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">reg</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rank</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">alpha</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rescale_cost</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'random'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reg_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">49</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rescale'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numItermax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2000</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stopThr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-07</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#lowrank_sinkhorn"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.lowrank.lowrank_sinkhorn" title="Link to this definition"></a></dt>
<dd><p>Solve the entropic regularization optimal transport problem under low-nonnegative rank constraints
on the couplings.</p>
<p>The function solves the following optimization problem:</p>
<div class="math notranslate nohighlight">
\[\mathop{\inf_{(\mathbf{Q},\mathbf{R},\mathbf{g}) \in \mathcal{C}(\mathbf{a},\mathbf{b},r)}} \langle \mathbf{C}, \mathbf{Q}\mathrm{diag}(1/\mathbf{g})\mathbf{R}^\top \rangle -
\mathrm{reg} \cdot H((\mathbf{Q}, \mathbf{R}, \mathbf{g}))\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{C}\)</span> is the (<cite>dim_a</cite>, <cite>dim_b</cite>) metric cost matrix</p></li>
<li><p><span class="math notranslate nohighlight">\(H((\mathbf{Q}, \mathbf{R}, \mathbf{g}))\)</span> is the values of the three respective entropies evaluated for each term.</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{Q}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{R}\)</span> are the low-rank matrix decomposition of the OT plan</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{g}\)</span> is the weight vector for the low-rank decomposition of the OT plan</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span> are source and target weights (histograms, both sum to 1)</p></li>
<li><p><span class="math notranslate nohighlight">\(r\)</span> is the rank of the OT plan</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathcal{C}(\mathbf{a}, \mathbf{b}, r)\)</span> are the low-rank couplings of the OT problem</p></li>
</ul>
<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_s</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim</em><em>)</em>) – samples in the source domain</p></li>
<li><p><strong>X_t</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>a</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>,</em><em>)</em>) – samples weights in the source domain</p></li>
<li><p><strong>b</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>,</em><em>)</em>) – samples weights in the target domain</p></li>
<li><p><strong>reg</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional</em>) – Regularization term >0</p></li>
<li><p><strong>rank</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is None.</em><em> (</em><em>>0</em><em>)</em>) – Nonnegative rank of the OT plan. If None, min(ns, nt) is considered.</p></li>
<li><p><strong>alpha</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is 1e-10.</em><em> (</em><em>>0 and <1/r</em><em>)</em>) – Lower bound for the weight vector g.</p></li>
<li><p><strong>rescale_cost</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional. Default is True</em>) – Rescale the low rank factorization of the sqeuclidean cost matrix</p></li>
<li><p><strong>init</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.14)"><em>str</em></a><em>, </em><em>optional. Default is 'random'.</em>) – Initialization strategy for the low rank couplings. ‘random’, ‘deterministic’ or ‘kmeans’</p></li>
<li><p><strong>reg_init</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional. Default is 1e-1.</em><em> (</em><em>>0</em><em>)</em>) – Regularization term for a ‘kmeans’ init. If None, 1 is considered.</p></li>
<li><p><strong>seed_init</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is 49.</em><em> (</em><em>>0</em><em>)</em>) – Random state for a ‘random’ or ‘kmeans’ init strategy.</p></li>
<li><p><strong>gamma_init</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.14)"><em>str</em></a><em>, </em><em>optional. Default is "rescale".</em>) – Initialization strategy for gamma. ‘rescale’, or ‘theory’
Gamma is a constant that scales the convergence criterion of the Mirror Descent
optimization scheme used to compute the low-rank couplings (Q, R and g)</p></li>
<li><p><strong>numItermax</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is 2000.</em>) – Max number of iterations for the Dykstra algorithm</p></li>
<li><p><strong>stopThr</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional. Default is 1e-7.</em>) – Stop threshold on error (>0) in Dykstra</p></li>
<li><p><strong>warn</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – if True, raises a warning if the algorithm doesn’t convergence.</p></li>
<li><p><strong>log</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – record log if True</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>Q</strong> (<em>array-like, shape (n_samples_a, r)</em>) – First low-rank matrix decomposition of the OT plan</p></li>
<li><p><strong>R</strong> (<em>array-like, shape (n_samples_b, r)</em>) – Second low-rank matrix decomposition of the OT plan</p></li>
<li><p><strong>g</strong> (<em>array-like, shape (r, )</em>) – Weight vector for the low-rank decomposition of the OT</p></li>
<li><p><strong>log</strong> (<em>dict (lazy_plan, value and value_linear)</em>) – log dictionary return only if log==True in parameters</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id2" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>65<span class="fn-bracket">]</span></span>
<p>Scetbon, M., Cuturi, M., & Peyré, G. (2021).
“Low-rank Sinkhorn Factorization”. In International Conference on Machine Learning.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.lowrank.sinkhorn_low_rank_kernel">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">sinkhorn_low_rank_kernel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">K1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</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">b</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">numItermax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1000</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stopThr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-09</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warmstart</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#sinkhorn_low_rank_kernel"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.lowrank.sinkhorn_low_rank_kernel" title="Link to this definition"></a></dt>
<dd><p>Compute the Sinkhorn algorithm for a kernel <span class="math notranslate nohighlight">\(\mathbf{K}\)</span> that can be written as a low rank factorization <span class="math notranslate nohighlight">\(\mathbf{K} = \mathbf{K}_1 \mathbf{K}_2^\top\)</span>.
Does not implement multiple targets.</p>
<p>Precisely :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{K}_1, \mathbf{K}_2\)</span> are the (<cite>dim_a</cite>, <cite>dim_r</cite>), (<cite>dim_b</cite>, <cite>dim_r</cite>) kernel matrices</p></li>
<li><p><span class="math notranslate nohighlight">\(\Omega\)</span> is the entropic regularization term
<span class="math notranslate nohighlight">\(\Omega(\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span> are source and target
weights (histograms, both sum to 1)</p></li>
</ul>
<p>The algorithm used for solving the problem is the Sinkhorn-Knopp
matrix scaling algorithm as proposed in <a class="reference internal" href="ot.bregman.html#references-sinkhorn-knopp"><span class="std std-ref">[2]</span></a></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>K_1</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim_r</em><em>)</em>) – Left factor</p></li>
<li><p><strong>K_2</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim_r</em><em>)</em>) – Right factor</p></li>
<li><p><strong>a</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>,</em><em>)</em>) – samples weights in the source domain</p></li>
<li><p><strong>b</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>,</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>numItermax</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional</em>) – Max number of iterations</p></li>
<li><p><strong>stopThr</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional</em>) – Stop threshold on error (>0)</p></li>
<li><p><strong>verbose</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – Print information along iterations</p></li>
<li><p><strong>log</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – record log if True</p></li>
<li><p><strong>warn</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – if True, raises a warning if the algorithm doesn’t convergence.</p></li>
<li><p><strong>warmstart</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.14)"><em>tuple</em></a><em> of </em><em>arrays</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>n_samples_b</em><em>)</em><em>, </em><em>optional</em>) – Initialization of dual potentials. If provided, the dual potentials should be given
(that is the logarithm of the u,v sinkhorn scaling vectors)</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>u</strong> (<em>array-like, shape (n_samples_a, )</em>) – Left dual variable</p></li>
<li><p><strong>v</strong> (<em>array-like, shape (n_samples_b, )</em>) – Right dual variable</p></li>
<li><p><strong>log</strong> (<em>dict (lazy_plan)</em>) – log dictionary return only if log==True in parameters</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
</section>
<section id="examples-using-ot-lowrank-sinkhorn-low-rank-kernel">
<h3>Examples using <code class="docutils literal notranslate"><span class="pre">ot.lowrank.sinkhorn_low_rank_kernel</span></code><a class="headerlink" href="#examples-using-ot-lowrank-sinkhorn-low-rank-kernel" title="Link to this heading"></a></h3>
<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="Shows how to use Nyström kernel approximation for approximating the Sinkhorn algorithm in linear time."><img alt="" src="../_images/sphx_glr_plot_nystroem_approximation_thumb.png" />
<p><a class="reference internal" href="../auto_examples/lowrank/plot_nystroem_approximation.html"><span class="doc">Nyström approximation for OT</span></a></p>
<div class="sphx-glr-thumbnail-title">Nyström approximation for OT</div>
</div></div><div class="sphx-glr-clear"></div></section>
</section>
<dl class="py function">
<dt class="sig sig-object py" id="id0">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">compute_lr_sqeuclidean_matrix</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X_s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">X_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rescale_cost</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">nx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#compute_lr_sqeuclidean_matrix"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id0" title="Link to this definition"></a></dt>
<dd><p>Compute the low rank decomposition of a squared euclidean distance matrix.
This function won’t work for other distance metrics.</p>
<p>See “Section 3.5, proposition 1”</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_s</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim</em><em>)</em>) – samples in the source domain</p></li>
<li><p><strong>X_t</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>rescale_cost</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a>) – Rescale the low rank factorization of the sqeuclidean cost matrix</p></li>
<li><p><strong>nx</strong> (<em>default None</em>) – POT backend</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>M1</strong> (<em>array-like, shape (n_samples_a, dim+2)</em>) – First low rank decomposition of the distance matrix</p></li>
<li><p><strong>M2</strong> (<em>array-like, shape (n_samples_b, dim+2)</em>) – Second low rank decomposition of the distance matrix</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id3" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>65<span class="fn-bracket">]</span></span>
<p>Scetbon, M., Cuturi, M., & Peyré, G. (2021).
“Low-rank Sinkhorn factorization”. In International Conference on Machine Learning.</p>
</aside>
</aside>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id4">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">kernel_nystroem</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X_s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">X_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">anchors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">50</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sigma</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">random_state</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#kernel_nystroem"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id4" title="Link to this definition"></a></dt>
<dd><p>Compute left and right factors corresponding to the Nystroem method on the Gaussian kernel <span class="math notranslate nohighlight">\(K(x^s_i, x^t_j) = \exp(-\|x^s_i-x^t_j\|^2/2\sigma^2)\)</span>.
The Nystroem approximation is computed by sampling <span class="math notranslate nohighlight">\(\min(n, \lceil(c / 2))\rceil)\)</span> components in each distribution,
where <span class="math notranslate nohighlight">\(n\)</span> is the number of samples in the distribution and <span class="math notranslate nohighlight">\(c\)</span> the total number of anchor points.</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_s</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim</em><em>)</em>) – samples in the source domain</p></li>
<li><p><strong>X_t</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>anchors</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional</em>) – The total number of anchors sampled for the Nystroem approximation (anchors/2 in each distribution), default 50.</p></li>
<li><p><strong>sigma</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional</em>) – The standard deviation parameter for the Gaussian kernel.</p></li>
<li><p><strong>random_state</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional</em>) – The random state for sampling the components in each distribution.</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>left_factor</strong> (<em>array-like, shape (n_samples_a, dim_r)</em>) – Left factor of Nystroem</p></li>
<li><p><strong>right_factor</strong> (<em>array-like, shape (n_samples_b, dim_r)</em>) – Right factor of Nystroem</p></li>
</ul>
</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id5">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">lowrank_sinkhorn</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">X_s</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">X_t</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</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">b</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">reg</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rank</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">alpha</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rescale_cost</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'random'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reg_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">seed_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">49</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma_init</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'rescale'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numItermax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2000</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stopThr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-07</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#lowrank_sinkhorn"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id5" title="Link to this definition"></a></dt>
<dd><p>Solve the entropic regularization optimal transport problem under low-nonnegative rank constraints
on the couplings.</p>
<p>The function solves the following optimization problem:</p>
<div class="math notranslate nohighlight">
\[\mathop{\inf_{(\mathbf{Q},\mathbf{R},\mathbf{g}) \in \mathcal{C}(\mathbf{a},\mathbf{b},r)}} \langle \mathbf{C}, \mathbf{Q}\mathrm{diag}(1/\mathbf{g})\mathbf{R}^\top \rangle -
\mathrm{reg} \cdot H((\mathbf{Q}, \mathbf{R}, \mathbf{g}))\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{C}\)</span> is the (<cite>dim_a</cite>, <cite>dim_b</cite>) metric cost matrix</p></li>
<li><p><span class="math notranslate nohighlight">\(H((\mathbf{Q}, \mathbf{R}, \mathbf{g}))\)</span> is the values of the three respective entropies evaluated for each term.</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{Q}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{R}\)</span> are the low-rank matrix decomposition of the OT plan</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{g}\)</span> is the weight vector for the low-rank decomposition of the OT plan</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span> are source and target weights (histograms, both sum to 1)</p></li>
<li><p><span class="math notranslate nohighlight">\(r\)</span> is the rank of the OT plan</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathcal{C}(\mathbf{a}, \mathbf{b}, r)\)</span> are the low-rank couplings of the OT problem</p></li>
</ul>
<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_s</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim</em><em>)</em>) – samples in the source domain</p></li>
<li><p><strong>X_t</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>a</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>,</em><em>)</em>) – samples weights in the source domain</p></li>
<li><p><strong>b</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>,</em><em>)</em>) – samples weights in the target domain</p></li>
<li><p><strong>reg</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional</em>) – Regularization term >0</p></li>
<li><p><strong>rank</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is None.</em><em> (</em><em>>0</em><em>)</em>) – Nonnegative rank of the OT plan. If None, min(ns, nt) is considered.</p></li>
<li><p><strong>alpha</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is 1e-10.</em><em> (</em><em>>0 and <1/r</em><em>)</em>) – Lower bound for the weight vector g.</p></li>
<li><p><strong>rescale_cost</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional. Default is True</em>) – Rescale the low rank factorization of the sqeuclidean cost matrix</p></li>
<li><p><strong>init</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.14)"><em>str</em></a><em>, </em><em>optional. Default is 'random'.</em>) – Initialization strategy for the low rank couplings. ‘random’, ‘deterministic’ or ‘kmeans’</p></li>
<li><p><strong>reg_init</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional. Default is 1e-1.</em><em> (</em><em>>0</em><em>)</em>) – Regularization term for a ‘kmeans’ init. If None, 1 is considered.</p></li>
<li><p><strong>seed_init</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is 49.</em><em> (</em><em>>0</em><em>)</em>) – Random state for a ‘random’ or ‘kmeans’ init strategy.</p></li>
<li><p><strong>gamma_init</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.14)"><em>str</em></a><em>, </em><em>optional. Default is "rescale".</em>) – Initialization strategy for gamma. ‘rescale’, or ‘theory’
Gamma is a constant that scales the convergence criterion of the Mirror Descent
optimization scheme used to compute the low-rank couplings (Q, R and g)</p></li>
<li><p><strong>numItermax</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional. Default is 2000.</em>) – Max number of iterations for the Dykstra algorithm</p></li>
<li><p><strong>stopThr</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional. Default is 1e-7.</em>) – Stop threshold on error (>0) in Dykstra</p></li>
<li><p><strong>warn</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – if True, raises a warning if the algorithm doesn’t convergence.</p></li>
<li><p><strong>log</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – record log if True</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>Q</strong> (<em>array-like, shape (n_samples_a, r)</em>) – First low-rank matrix decomposition of the OT plan</p></li>
<li><p><strong>R</strong> (<em>array-like, shape (n_samples_b, r)</em>) – Second low-rank matrix decomposition of the OT plan</p></li>
<li><p><strong>g</strong> (<em>array-like, shape (r, )</em>) – Weight vector for the low-rank decomposition of the OT</p></li>
<li><p><strong>log</strong> (<em>dict (lazy_plan, value and value_linear)</em>) – log dictionary return only if log==True in parameters</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id6" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>65<span class="fn-bracket">]</span></span>
<p>Scetbon, M., Cuturi, M., & Peyré, G. (2021).
“Low-rank Sinkhorn Factorization”. In International Conference on Machine Learning.</p>
</aside>
</aside>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id7">
<span class="sig-prename descclassname"><span class="pre">ot.lowrank.</span></span><span class="sig-name descname"><span class="pre">sinkhorn_low_rank_kernel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">K1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">K2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">a</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">b</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">numItermax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1000</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stopThr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1e-09</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">verbose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warn</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">warmstart</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/lowrank.html#sinkhorn_low_rank_kernel"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id7" title="Link to this definition"></a></dt>
<dd><p>Compute the Sinkhorn algorithm for a kernel <span class="math notranslate nohighlight">\(\mathbf{K}\)</span> that can be written as a low rank factorization <span class="math notranslate nohighlight">\(\mathbf{K} = \mathbf{K}_1 \mathbf{K}_2^\top\)</span>.
Does not implement multiple targets.</p>
<p>Precisely :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{K}_1, \mathbf{K}_2\)</span> are the (<cite>dim_a</cite>, <cite>dim_r</cite>), (<cite>dim_b</cite>, <cite>dim_r</cite>) kernel matrices</p></li>
<li><p><span class="math notranslate nohighlight">\(\Omega\)</span> is the entropic regularization term
<span class="math notranslate nohighlight">\(\Omega(\gamma)=\sum_{i,j} \gamma_{i,j}\log(\gamma_{i,j})\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span> are source and target
weights (histograms, both sum to 1)</p></li>
</ul>
<p>The algorithm used for solving the problem is the Sinkhorn-Knopp
matrix scaling algorithm as proposed in <a class="reference internal" href="ot.bregman.html#references-sinkhorn-knopp"><span class="std std-ref">[2]</span></a></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>K_1</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>dim_r</em><em>)</em>) – Left factor</p></li>
<li><p><strong>K_2</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>, </em><em>dim_r</em><em>)</em>) – Right factor</p></li>
<li><p><strong>a</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>,</em><em>)</em>) – samples weights in the source domain</p></li>
<li><p><strong>b</strong> (<em>array-like</em><em>, </em><em>shape</em><em> (</em><em>n_samples_b</em><em>,</em><em>)</em>) – samples in the target domain</p></li>
<li><p><strong>numItermax</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.14)"><em>int</em></a><em>, </em><em>optional</em>) – Max number of iterations</p></li>
<li><p><strong>stopThr</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.14)"><em>float</em></a><em>, </em><em>optional</em>) – Stop threshold on error (>0)</p></li>
<li><p><strong>verbose</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – Print information along iterations</p></li>
<li><p><strong>log</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – record log if True</p></li>
<li><p><strong>warn</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(in Python v3.14)"><em>bool</em></a><em>, </em><em>optional</em>) – if True, raises a warning if the algorithm doesn’t convergence.</p></li>
<li><p><strong>warmstart</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.14)"><em>tuple</em></a><em> of </em><em>arrays</em><em>, </em><em>shape</em><em> (</em><em>n_samples_a</em><em>, </em><em>n_samples_b</em><em>)</em><em>, </em><em>optional</em>) – Initialization of dual potentials. If provided, the dual potentials should be given
(that is the logarithm of the u,v sinkhorn scaling vectors)</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>u</strong> (<em>array-like, shape (n_samples_a, )</em>) – Left dual variable</p></li>
<li><p><strong>v</strong> (<em>array-like, shape (n_samples_b, )</em>) – Right dual variable</p></li>
<li><p><strong>log</strong> (<em>dict (lazy_plan)</em>) – log dictionary return only if log==True in parameters</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.gromov.html" class="btn btn-neutral float-left" title="ot.gromov" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="ot.lp.html" class="btn btn-neutral float-right" title="ot.lp" 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.7
<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>