Repository navigation
Expand file tree
/
Copy pathot.regpath.html
More file actions
1494 lines (1434 loc) · 149 KB
/
Copy pathot.regpath.html
File metadata and controls
1494 lines (1434 loc) · 149 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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!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.regpath — 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.sliced" href="ot.sliced.html" />
<link rel="prev" title="ot.plot" href="ot.plot.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"><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 current"><a class="current reference internal" href="#">ot.regpath</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.regpath.complement_schur"><code class="docutils literal notranslate"><span class="pre">complement_schur()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#ot.regpath.compute_next_removal"><code class="docutils literal notranslate"><span class="pre">compute_next_removal()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#ot.regpath.compute_transport_plan"><code class="docutils literal notranslate"><span class="pre">compute_transport_plan()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#examples-using-ot-regpath-compute-transport-plan">Examples using <code class="docutils literal notranslate"><span class="pre">ot.regpath.compute_transport_plan</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#examples-using-ot-regpath-regularization-path">Examples using <code class="docutils literal notranslate"><span class="pre">ot.regpath.regularization_path</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#id0"><code class="docutils literal notranslate"><span class="pre">complement_schur()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id12"><code class="docutils literal notranslate"><span class="pre">compute_next_removal()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id15"><code class="docutils literal notranslate"><span class="pre">compute_transport_plan()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id18"><code class="docutils literal notranslate"><span class="pre">construct_augmented_H()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id19"><code class="docutils literal notranslate"><span class="pre">fully_relaxed_path()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id21"><code class="docutils literal notranslate"><span class="pre">ot_next_gamma()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id23"><code class="docutils literal notranslate"><span class="pre">recast_ot_as_lasso()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id25"><code class="docutils literal notranslate"><span class="pre">recast_semi_relaxed_as_lasso()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id26"><code class="docutils literal notranslate"><span class="pre">regularization_path()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id28"><code class="docutils literal notranslate"><span class="pre">semi_relaxed_next_gamma()</span></code></a></li>
<li class="toctree-l3"><a class="reference internal" href="#id30"><code class="docutils literal notranslate"><span class="pre">semi_relaxed_path()</span></code></a></li>
</ul>
</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.regpath</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/gen_modules/ot.regpath.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.regpath">
<span id="ot-regpath"></span><h1>ot.regpath<a class="headerlink" href="#module-ot.regpath" title="Link to this heading"></a></h1>
<p>Regularization path 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.regpath.complement_schur">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">complement_schur</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">M_current</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">id_pop</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#complement_schur"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.complement_schur" title="Link to this definition"></a></dt>
<dd><p>This function computes the inverse of the design matrix in the regularization path using the Schur complement. Two cases may arise:</p>
<p>Case 1: one variable is added to the active set</p>
<div class="math notranslate nohighlight">
\[\begin{split}M_{k+1}^{-1} =
\begin{bmatrix}
M_{k}^{-1} + s^{-1} M_{k}^{-1} \mathbf{b} \mathbf{b}^T M_{k}^{-1} \
& - M_{k}^{-1} \mathbf{b} s^{-1} \\
- s^{-1} \mathbf{b}^T M_{k}^{-1} & s^{-1}
\end{bmatrix}\end{split}\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(M_k^{-1}\)</span> is the inverse of the design matrix <span class="math notranslate nohighlight">\(H_A^tH_A\)</span> of the previous iteration</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{b}\)</span> is the last column of <span class="math notranslate nohighlight">\(M_{k}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(s\)</span> is the Schur complement, given by <span class="math notranslate nohighlight">\(s = \mathbf{d} - \mathbf{b}^T M_{k}^{-1} \mathbf{b}\)</span></p></li>
</ul>
<p>Case 2: one variable is removed from the active set.</p>
<div class="math notranslate nohighlight">
\[M_{k+1}^{-1} = M^{-1}_{k \backslash q} -
\frac{r_{-q,q} r^{T}_{-q,q}}{r_{q,q}}\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(q\)</span> is the index of column and row to delete</p></li>
<li><p><span class="math notranslate nohighlight">\(M^{-1}_{k \backslash q}\)</span> is the previous inverse matrix deprived of the <span class="math notranslate nohighlight">\(q\)</span> th column and <span class="math notranslate nohighlight">\(q\)</span> th row</p></li>
<li><p><span class="math notranslate nohighlight">\(r_{-q,q}\)</span> is the <span class="math notranslate nohighlight">\(q\)</span> th column of <span class="math notranslate nohighlight">\(M^{-1}_{k}\)</span> without the <span class="math notranslate nohighlight">\(q\)</span> th element</p></li>
<li><p><span class="math notranslate nohighlight">\(r_{q, q}\)</span> is the element of <span class="math notranslate nohighlight">\(q\)</span> th column and <span class="math notranslate nohighlight">\(q\)</span> th row in <span class="math notranslate nohighlight">\(M^{-1}_{k}\)</span></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>M_current</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>-1</em><em>, </em><em>size</em><em>(</em><em>A</em><em>)</em><em>-1</em><em>)</em>) – Inverse matrix of <span class="math notranslate nohighlight">\(H_A^tH_A\)</span> at the previous iteration, with size(A) the size of the active set</p></li>
<li><p><strong>b</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>-1</em><em>, </em><em>)</em>) – None for case 2 (removal), last column of <span class="math notranslate nohighlight">\(M_{k}\)</span> for case 1 (addition)</p></li>
<li><p><strong>d</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – should be equal to 2 when UOT and 1 for the semi-relaxed OT</p></li>
<li><p><strong>id_pop</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a>) – Index of the variable to be removed, equal to -1
if no variable is deleted at the current iteration</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>M</strong> – Inverse matrix of <span class="math notranslate nohighlight">\(H_A^tH_A\)</span> of the current iteration</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>ndarray, shape (size(A), size(A))</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>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.compute_next_removal">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">compute_next_removal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">phi</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">current_gamma</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#compute_next_removal"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.compute_next_removal" title="Link to this definition"></a></dt>
<dd><p>This function computes the next gamma value if a variable
is removed at the next iteration of the regularization path.</p>
<p>We look for the largest value of the regularization parameter such that
an element of the current solution vanishes</p>
<div class="math notranslate nohighlight">
\[\max_{j \in A} \frac{\phi_j}{\delta_j}\]</div>
<p>where :</p>
<ul class="simple">
<li><p>A is the current active set</p></li>
<li><p><span class="math notranslate nohighlight">\(\phi_j\)</span> is the <span class="math notranslate nohighlight">\(j\)</span> th element of the intercept of the current solution</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta_j\)</span> is the <span class="math notranslate nohighlight">\(j\)</span> th element of the slope of the current solution</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>phi</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Intercept of the solution at the current iteration</p></li>
<li><p><strong>delta</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Slope of the solution at the current iteration</p></li>
<li><p><strong>current_gamma</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – Value of the regularization parameter at the beginning of the current iteration</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>next_removal_gamma</strong> (<em>float</em>) – Gamma value if a variable is removed at the next iteration</p></li>
<li><p><strong>next_removal_index</strong> (<em>int</em>) – Index of the variable to be removed at the next iteration</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric" id="references-regpath">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id2" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.compute_transport_plan">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">compute_transport_plan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gamma</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma_list</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Pi_list</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#compute_transport_plan"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.compute_transport_plan" title="Link to this definition"></a></dt>
<dd><p>Given the regularization path, this function computes the transport
plan for any value of gamma thanks to the piecewise linearity of the path.</p>
<div class="math notranslate nohighlight">
\[t(\gamma) = \phi(\gamma) - \gamma \delta(\gamma)\]</div>
<p>where:</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\gamma\)</span> is the regularization parameter</p></li>
<li><p><span class="math notranslate nohighlight">\(\phi(\gamma)\)</span> is the corresponding intercept</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta(\gamma)\)</span> is the corresponding slope</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport matrix</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>gamma</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – Regularization coefficient</p></li>
<li><p><strong>gamma_list</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – List of regularization parameters of the regularization path</p></li>
<li><p><strong>Pi_list</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – List of all the solutions of the regularization path</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>t</strong> – Vectorization of the transport plan corresponding to the given value
of gamma</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>np.ndarray (dim_a*dim_b, )</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">ot</span>
<span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="gp">>>> </span><span class="n">n</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">xs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">xt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">5.</span><span class="p">,</span> <span class="mf">6.</span><span class="p">,</span> <span class="mf">7.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">dist</span><span class="p">(</span><span class="n">xs</span><span class="p">,</span> <span class="n">xt</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">/=</span> <span class="n">C</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">,</span> <span class="n">pi_list</span><span class="p">,</span> <span class="n">g_list</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">regularization_path</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="n">reg</span><span class="o">=</span><span class="mf">1e-4</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">gamma</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">>>> </span><span class="n">t2</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">compute_transport_plan</span><span class="p">(</span><span class="n">gamma</span><span class="p">,</span> <span class="n">g_list</span><span class="p">,</span> <span class="n">pi_list</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">t2</span>
<span class="go">array([0. , 0. , 0. , 0.19722222, 0.05555556,</span>
<span class="go"> 0. , 0. , 0.24722222, 0. ])</span>
</pre></div>
</div>
<p class="rubric" id="id3">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id4" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<section id="examples-using-ot-regpath-compute-transport-plan">
<h3>Examples using <code class="docutils literal notranslate"><span class="pre">ot.regpath.compute_transport_plan</span></code><a class="headerlink" href="#examples-using-ot-regpath-compute-transport-plan" title="Link to this heading"></a></h3>
<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the regularization path for 2D unbalanced optimal transport. We present here both the fully relaxed case and the semi-relaxed case."><img alt="" src="../_images/sphx_glr_plot_regpath_thumb.png" />
<p><a class="reference internal" href="../auto_examples/unbalanced-partial/plot_regpath.html"><span class="doc">Regularization path of l2-penalized unbalanced optimal transport</span></a></p>
<div class="sphx-glr-thumbnail-title">Regularization path of l2-penalized unbalanced optimal transport</div>
</div></div><div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.construct_augmented_H">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">construct_augmented_H</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">active_index</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Hc</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">HrHr</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#construct_augmented_H"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.construct_augmented_H" title="Link to this definition"></a></dt>
<dd><p>This function constructs an augmented matrix for the first iteration
of the semi-relaxed regularization path</p>
<div class="math notranslate nohighlight">
\[\begin{split}\text{Augmented}_H =
\begin{bmatrix}
0 & H_{c A} \\
H_{c A}^T & H_{r A}^T H_{r A}
\end{bmatrix}\end{split}\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(H_{r A}\)</span> is the sub-matrix constructed by the columns of <span class="math notranslate nohighlight">\(H_r\)</span> whose indices belong to the active set A</p></li>
<li><p><span class="math notranslate nohighlight">\(H_{c A}\)</span> is the sub-matrix constructed by the columns of <span class="math notranslate nohighlight">\(H_c\)</span> whose indices belong to the active set A</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>active_index</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – Indices of the active variables</p></li>
<li><p><strong>m</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a>) – Length of the target distribution</p></li>
<li><p><strong>Hc</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix that computes the sum along the columns of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><strong>HrHr</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix product of <span class="math notranslate nohighlight">\(H_r^T H_r\)</span></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>H_augmented</strong> – Augmented matrix for the first iteration of the semi-relaxed
regularization path</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>np.ndarray (dim_b + size(A), dim_b + size(A))</p>
</dd>
</dl>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.fully_relaxed_path">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">fully_relaxed_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">C</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</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.0001</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">itmax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">50000</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#fully_relaxed_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.fully_relaxed_path" title="Link to this definition"></a></dt>
<dd><p>This function gives the regularization path of l2-penalized UOT problem</p>
<p>The problem to optimize is the Lasso reformulation of the l2-penalized UOT:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\min_t \gamma \mathbf{c}^T \mathbf{t}
+ 0.5 * \|{H} \mathbf{t} - \mathbf{y}\|_2^2\\s.t.
\mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}\)</span> is the flattened version of the cost matrix <span class="math notranslate nohighlight">\({C}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gamma = 1/\lambda\)</span> is the l2-regularization coefficient</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{y}\)</span> is the concatenation of vectors <span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span>, defined as <span class="math notranslate nohighlight">\(\mathbf{y}^T = [\mathbf{a}^T \mathbf{b}^T]\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\({H}\)</span> is a design matrix, see <a class="reference internal" href="ot.unbalanced.html#references-regpath"><span class="std std-ref">[41]</span></a> for the design of <span class="math notranslate nohighlight">\({H}\)</span>. The matrix product <span class="math notranslate nohighlight">\(H\mathbf{t}\)</span> computes both the source marginal and the target marginals.</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport matrix</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>a</strong> (<em>np.ndarray</em><em> (</em><em>dim_a</em><em>,</em><em>)</em>) – Histogram of dimension dim_a</p></li>
<li><p><strong>b</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>,</em><em>)</em>) – Histogram of dimension dim_b</p></li>
<li><p><strong>C</strong> (<em>np.ndarray</em><em>, </em><em>shape</em><em> (</em><em>dim_a</em><em>, </em><em>dim_b</em><em>)</em>) – Cost matrix</p></li>
<li><p><strong>reg</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – l2-regularization coefficient</p></li>
<li><p><strong>itmax</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a>) – Maximum number of iteration</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>t</strong> (<em>np.ndarray (dim_a*dim_b, )</em>) – Flattened vector of the optimal transport matrix</p></li>
<li><p><strong>t_list</strong> (<em>list</em>) – List of solutions in the regularization path</p></li>
<li><p><strong>gamma_list</strong> (<em>list</em>) – List of regularization coefficients in the regularization path</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">ot</span>
<span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="gp">>>> </span><span class="n">n</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">xs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">xt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">5.</span><span class="p">,</span> <span class="mf">6.</span><span class="p">,</span> <span class="mf">7.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">dist</span><span class="p">(</span><span class="n">xs</span><span class="p">,</span> <span class="n">xt</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">/=</span> <span class="n">C</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">fully_relaxed_path</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="mf">1e-4</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">t</span>
<span class="go">array([1.99958333e-01, 0.00000000e+00, 0.00000000e+00, 3.88888889e-05,</span>
<span class="go"> 4.99938889e-01, 0.00000000e+00, 0.00000000e+00, 3.88888889e-05,</span>
<span class="go"> 2.99958333e-01])</span>
</pre></div>
</div>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id5" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.ot_next_gamma">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">ot_next_gamma</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">phi</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">HtH</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Hty</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">active_index</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">current_gamma</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#ot_next_gamma"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.ot_next_gamma" title="Link to this definition"></a></dt>
<dd><p>This function computes the next value of gamma if a variable
is added in the next iteration of the regularization path.</p>
<p>We look for the largest value of gamma such that
the gradient of an inactive variable vanishes</p>
<div class="math notranslate nohighlight">
\[\max_{i \in \bar{A}} \frac{\mathbf{h}_i^T(H_A \phi - \mathbf{y})}
{\mathbf{h}_i^T H_A \delta - \mathbf{c}_i}\]</div>
<p>where :</p>
<ul class="simple">
<li><p>A is the current active set</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{h}_i\)</span> is the <span class="math notranslate nohighlight">\(i\)</span> th column of the design matrix <span class="math notranslate nohighlight">\({H}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\({H}_A\)</span> is the sub-matrix constructed by the columns of <span class="math notranslate nohighlight">\({H}\)</span> whose indices belong to the active set A</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}_i\)</span> is the <span class="math notranslate nohighlight">\(i\)</span> th element of the cost vector <span class="math notranslate nohighlight">\(\mathbf{c}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{y}\)</span> is the concatenation of the source and target distributions</p></li>
<li><p><span class="math notranslate nohighlight">\(\phi\)</span> is the intercept of the solutions at the current iteration</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta\)</span> is the slope of the solutions at the current iteration</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>phi</strong> (<em>np.ndarray</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Intercept of the solutions at the current iteration</p></li>
<li><p><strong>delta</strong> (<em>np.ndarray</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Slope of the solutions at the current iteration</p></li>
<li><p><strong>HtH</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix product of <span class="math notranslate nohighlight">\({H}^T {H}\)</span></p></li>
<li><p><strong>Hty</strong> (<em>np.ndarray</em><em> (</em><em>dim_a + dim_b</em><em>, </em><em>)</em>) – Matrix product of <span class="math notranslate nohighlight">\({H}^T \mathbf{y}\)</span></p></li>
<li><p><strong>c</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>)</em>) – Flattened array of the cost matrix <span class="math notranslate nohighlight">\({C}\)</span></p></li>
<li><p><strong>active_index</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – Indices of active variables</p></li>
<li><p><strong>current_gamma</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – Value of the regularization parameter at the beginning of the current iteration</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>next_gamma</strong> (<em>float</em>) – Value of gamma if a variable is added to active set in next iteration</p></li>
<li><p><strong>next_active_index</strong> (<em>int</em>) – Index of variable to be activated</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>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.recast_ot_as_lasso">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">recast_ot_as_lasso</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">C</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#recast_ot_as_lasso"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.recast_ot_as_lasso" title="Link to this definition"></a></dt>
<dd><p>This function recasts the l2-penalized UOT problem as a Lasso problem.</p>
<p>Recall the l2-penalized UOT problem defined in
<a class="reference internal" href="ot.unbalanced.html#references-regpath"><span class="std std-ref">[41]</span></a></p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\text{UOT}_{\lambda} = \min_T <C, T> + \lambda \|T 1_m -
\mathbf{a}\|_2^2 +
\lambda \|T^T 1_n - \mathbf{b}\|_2^2\\s.t.
T \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(C\)</span> is the cost matrix</p></li>
<li><p><span class="math notranslate nohighlight">\(\lambda\)</span> is the l2-regularization parameter</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span> are the source and target distributions</p></li>
<li><p><span class="math notranslate nohighlight">\(T\)</span> is the transport plan to optimize</p></li>
</ul>
<p>The problem above can be reformulated as a non-negative penalized
linear regression problem, particularly Lasso</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\text{UOT2}_{\lambda} = \min_{\mathbf{t}} \gamma \mathbf{c}^T
\mathbf{t} + 0.5 * \|H \mathbf{t} - \mathbf{y}\|_2^2\\s.t.
\mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}\)</span> is the flattened version of the cost matrix <span class="math notranslate nohighlight">\(C\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{y}\)</span> is the concatenation of vectors <span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(H\)</span> is a metric matrix, see <a class="reference internal" href="ot.unbalanced.html#references-regpath"><span class="std std-ref">[41]</span></a> for the design of <span class="math notranslate nohighlight">\(H\)</span>. The matrix product <span class="math notranslate nohighlight">\(H\mathbf{t}\)</span> computes both the source marginal and the target marginals.</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport plan <span class="math notranslate nohighlight">\(T\)</span></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>a</strong> (<em>np.ndarray</em><em> (</em><em>dim_a</em><em>,</em><em>)</em>) – Histogram of dimension dim_a</p></li>
<li><p><strong>b</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>,</em><em>)</em>) – Histogram of dimension dim_b</p></li>
<li><p><strong>C</strong> (<em>np.ndarray</em><em>, </em><em>shape</em><em> (</em><em>dim_a</em><em>, </em><em>dim_b</em><em>)</em>) – Cost matrix</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>H</strong> (<em>np.ndarray (dim_a+dim_b, dim_a*dim_b)</em>) – Design matrix that contains only 0 and 1</p></li>
<li><p><strong>y</strong> (<em>np.ndarray (ns + nt, )</em>) – Concatenation of histograms <span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span></p></li>
<li><p><strong>c</strong> (<em>np.ndarray (ns * nt, )</em>) – Flattened array of the cost matrix</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">ot</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">16.</span><span class="p">,</span> <span class="mf">25.</span><span class="p">],</span> <span class="p">[</span><span class="mf">28.</span><span class="p">,</span> <span class="mf">16.</span><span class="p">],</span> <span class="p">[</span><span class="mf">40.</span><span class="p">,</span> <span class="mf">36.</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">H</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">recast_ot_as_lasso</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">C</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">H</span><span class="o">.</span><span class="n">toarray</span><span class="p">()</span>
<span class="go">array([[1., 1., 0., 0., 0., 0.],</span>
<span class="go"> [0., 0., 1., 1., 0., 0.],</span>
<span class="go"> [0., 0., 0., 0., 1., 1.],</span>
<span class="go"> [1., 0., 1., 0., 1., 0.],</span>
<span class="go"> [0., 1., 0., 1., 0., 1.]])</span>
<span class="gp">>>> </span><span class="n">y</span>
<span class="go">array([0.2, 0.3, 0.5, 0.1, 0.9])</span>
<span class="gp">>>> </span><span class="n">c</span>
<span class="go">array([16., 25., 28., 16., 40., 36.])</span>
</pre></div>
</div>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id7" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.recast_semi_relaxed_as_lasso">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">recast_semi_relaxed_as_lasso</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">C</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#recast_semi_relaxed_as_lasso"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.recast_semi_relaxed_as_lasso" title="Link to this definition"></a></dt>
<dd><p>This function recasts the semi-relaxed l2-UOT problem as Lasso problem.</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\text{semi-relaxed UOT} = \min_T <C, T>
+ \lambda \|T 1_m - \mathbf{a}\|_2^2\\s.t.
T^T 1_n = \mathbf{b}\\ \mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(C\)</span> is the metric cost matrix</p></li>
<li><p><span class="math notranslate nohighlight">\(\lambda\)</span> is the l2-regularization parameter</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span> are the source and target distributions</p></li>
<li><p><span class="math notranslate nohighlight">\(T\)</span> is the transport plan to optimize</p></li>
</ul>
<p>The problem above can be reformulated as follows</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\text{semi-relaxed UOT2} = \min_t \gamma \mathbf{c}^T t
+ 0.5 * \|H_r \mathbf{t} - \mathbf{a}\|_2^2\\s.t.
H_c \mathbf{t} = \mathbf{b}\\ \mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}\)</span> is flattened version of the cost matrix <span class="math notranslate nohighlight">\(C\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gamma = 1/\lambda\)</span> is the l2-regularization parameter</p></li>
<li><p><span class="math notranslate nohighlight">\(H_r\)</span> is a metric matrix which computes the sum along the rows of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(H_c\)</span> is a metric matrix which computes the sum along the columns of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of <span class="math notranslate nohighlight">\(T\)</span></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>a</strong> (<em>np.ndarray</em><em> (</em><em>dim_a</em><em>,</em><em>)</em>) – Histogram of dimension dim_a</p></li>
<li><p><strong>b</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>,</em><em>)</em>) – Histogram of dimension dim_b</p></li>
<li><p><strong>C</strong> (<em>np.ndarray</em><em>, </em><em>shape</em><em> (</em><em>dim_a</em><em>, </em><em>dim_b</em><em>)</em>) – Cost matrix</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>Hr</strong> (<em>np.ndarray (dim_a, dim_a * dim_b)</em>) – Auxiliary matrix constituted by 0 and 1, which computes
the sum along the rows of transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><strong>Hc</strong> (<em>np.ndarray (dim_b, dim_a * dim_b)</em>) – Auxiliary matrix constituted by 0 and 1, which computes
the sum along the columns of transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><strong>c</strong> (<em>np.ndarray (ns * nt, )</em>) – Flattened array of the cost matrix</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">ot</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.1</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mf">16.</span><span class="p">,</span> <span class="mf">25.</span><span class="p">],</span> <span class="p">[</span><span class="mf">28.</span><span class="p">,</span> <span class="mf">16.</span><span class="p">],</span> <span class="p">[</span><span class="mf">40.</span><span class="p">,</span> <span class="mf">36.</span><span class="p">]])</span>
<span class="gp">>>> </span><span class="n">Hr</span><span class="p">,</span><span class="n">Hc</span><span class="p">,</span><span class="n">c</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">recast_semi_relaxed_as_lasso</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">C</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">Hr</span><span class="o">.</span><span class="n">toarray</span><span class="p">()</span>
<span class="go">array([[1., 1., 0., 0., 0., 0.],</span>
<span class="go"> [0., 0., 1., 1., 0., 0.],</span>
<span class="go"> [0., 0., 0., 0., 1., 1.]])</span>
<span class="gp">>>> </span><span class="n">Hc</span><span class="o">.</span><span class="n">toarray</span><span class="p">()</span>
<span class="go">array([[1., 0., 1., 0., 1., 0.],</span>
<span class="go"> [0., 1., 0., 1., 0., 1.]])</span>
<span class="gp">>>> </span><span class="n">c</span>
<span class="go">array([16., 25., 28., 16., 40., 36.])</span>
</pre></div>
</div>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.regularization_path">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">regularization_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">C</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</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.0001</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">semi_relaxed</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">itmax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">50000</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#regularization_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.regularization_path" title="Link to this definition"></a></dt>
<dd><p>This function provides all the solutions of the regularization path of the l2-UOT problem <a class="reference internal" href="ot.unbalanced.html#references-regpath"><span class="std std-ref">[41]</span></a>.</p>
<p>The problem to optimize is the Lasso reformulation of the l2-penalized UOT:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\min_t \gamma \mathbf{c}^T \mathbf{t}
+ 0.5 * \|{H} \mathbf{t} - \mathbf{y}\|_2^2\\s.t.
\mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}\)</span> is the flattened version of the cost matrix <span class="math notranslate nohighlight">\({C}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gamma = 1/\lambda\)</span> is the l2-regularization coefficient</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{y}\)</span> is the concatenation of vectors <span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span>, defined as <span class="math notranslate nohighlight">\(\mathbf{y}^T = [\mathbf{a}^T \mathbf{b}^T]\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\({H}\)</span> is a design matrix, see <a class="reference internal" href="ot.unbalanced.html#references-regpath"><span class="std std-ref">[41]</span></a> for the design of <span class="math notranslate nohighlight">\({H}\)</span>. The matrix product <span class="math notranslate nohighlight">\(H\mathbf{t}\)</span> computes both the source marginal and the target marginals.</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport matrix</p></li>
</ul>
<p>For the semi-relaxed problem, it optimizes the Lasso reformulation of the
l2-penalized UOT:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\min_t \gamma \mathbf{c}^T \mathbf{t}
+ 0.5 * \|H_r \mathbf{t} - \mathbf{a}\|_2^2\\s.t.
H_c \mathbf{t} = \mathbf{b}\\ \mathbf{t} \geq 0\end{aligned}\end{align} \]</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>a</strong> (<em>np.ndarray</em><em> (</em><em>dim_a</em><em>,</em><em>)</em>) – Histogram of dimension dim_a</p></li>
<li><p><strong>b</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>,</em><em>)</em>) – Histogram of dimension dim_b</p></li>
<li><p><strong>C</strong> (<em>np.ndarray</em><em>, </em><em>shape</em><em> (</em><em>dim_a</em><em>, </em><em>dim_b</em><em>)</em>) – Cost matrix</p></li>
<li><p><strong>reg</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a><em> (</em><em>optional</em><em>)</em>) – l2-regularization coefficient</p></li>
<li><p><strong>semi_relaxed</strong> (<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><em>)</em>) – Give the semi-relaxed path if True</p></li>
<li><p><strong>itmax</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><em>)</em>) – Maximum number of iteration</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>t</strong> (<em>np.ndarray (dim_a*dim_b, )</em>) – Flattened vector of the (unregularized) optimal transport matrix</p></li>
<li><p><strong>t_list</strong> (<em>list</em>) – List of all the optimal transport vectors of the regularization path</p></li>
<li><p><strong>gamma_list</strong> (<em>list</em>) – List of the regularization parameters in the path</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id8" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
</section>
<section id="examples-using-ot-regpath-regularization-path">
<h3>Examples using <code class="docutils literal notranslate"><span class="pre">ot.regpath.regularization_path</span></code><a class="headerlink" href="#examples-using-ot-regpath-regularization-path" title="Link to this heading"></a></h3>
<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="This example illustrate the regularization path for 2D unbalanced optimal transport. We present here both the fully relaxed case and the semi-relaxed case."><img alt="" src="../_images/sphx_glr_plot_regpath_thumb.png" />
<p><a class="reference internal" href="../auto_examples/unbalanced-partial/plot_regpath.html"><span class="doc">Regularization path of l2-penalized unbalanced optimal transport</span></a></p>
<div class="sphx-glr-thumbnail-title">Regularization path of l2-penalized unbalanced optimal transport</div>
</div></div><div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.semi_relaxed_next_gamma">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">semi_relaxed_next_gamma</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">phi</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">phi_u</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delta_u</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">HrHr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Hc</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Hra</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">c</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">active_index</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">current_gamma</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#semi_relaxed_next_gamma"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.semi_relaxed_next_gamma" title="Link to this definition"></a></dt>
<dd><p>This function computes the next value of gamma when a variable is
active in the regularization path of semi-relaxed UOT.</p>
<p>By taking the Lagrangian form of the problem, we obtain a similar update
as the two-sided relaxed UOT</p>
<div class="math notranslate nohighlight">
\[\max_{i \in \bar{A}} \frac{\mathbf{h}_{ri}^T(H_{rA} \phi - \mathbf{a})
+ \mathbf{h}_{c i}^T\phi_u}{\mathbf{h}_{r i}^T H_{r A} \delta + \
\mathbf{h}_{c i} \delta_u - \mathbf{c}_i}\]</div>
<p>where :</p>
<ul class="simple">
<li><p>A is the current active set</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{h}_{r i}\)</span> is the ith column of the matrix <span class="math notranslate nohighlight">\(H_r\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{h}_{c i}\)</span> is the ith column of the matrix <span class="math notranslate nohighlight">\(H_c\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(H_{r A}\)</span> is the sub-matrix constructed by the columns of <span class="math notranslate nohighlight">\(H_r\)</span> whose indices belong to the active set A</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}_i\)</span> is the <span class="math notranslate nohighlight">\(i\)</span> th element of cost vector <span class="math notranslate nohighlight">\(\mathbf{c}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\phi\)</span> is the intercept of the solutions in current iteration</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta\)</span> is the slope of the solutions in current iteration</p></li>
<li><p><span class="math notranslate nohighlight">\(\phi_u\)</span> is the intercept of Lagrange parameter at the current iteration</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta_u\)</span> is the slope of Lagrange parameter at the current iteration</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>phi</strong> (<em>np.ndarray</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Intercept of the solutions at the current iteration</p></li>
<li><p><strong>delta</strong> (<em>np.ndarray</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Slope of the solutions at the current iteration</p></li>
<li><p><strong>phi_u</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>, </em><em>)</em>) – Intercept of the Lagrange parameter at the current iteration</p></li>
<li><p><strong>delta_u</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>, </em><em>)</em>) – Slope of the Lagrange parameter at the current iteration</p></li>
<li><p><strong>HrHr</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix product of <span class="math notranslate nohighlight">\(H_r^T H_r\)</span></p></li>
<li><p><strong>Hc</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix that computes the sum along the columns of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><strong>Hra</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>)</em>) – Matrix product of <span class="math notranslate nohighlight">\(H_r^T \mathbf{a}\)</span></p></li>
<li><p><strong>c</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>)</em>) – Flattened array of cost matrix <span class="math notranslate nohighlight">\(C\)</span></p></li>
<li><p><strong>active_index</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – Indices of active variables</p></li>
<li><p><strong>current_gamma</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – Value of regularization coefficient at the start of current iteration</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>next_gamma</strong> (<em>float</em>) – Value of gamma if a variable is added to active set in next iteration</p></li>
<li><p><strong>next_active_index</strong> (<em>int</em>) – Index of variable to be activated</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id9" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<div class="sphx-glr-clear"></div><dl class="py function">
<dt class="sig sig-object py" id="ot.regpath.semi_relaxed_path">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">semi_relaxed_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">C</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</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.0001</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">itmax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">50000</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#semi_relaxed_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#ot.regpath.semi_relaxed_path" title="Link to this definition"></a></dt>
<dd><p>This function gives the regularization path of semi-relaxed
l2-UOT problem.</p>
<p>The problem to optimize is the Lasso reformulation of the l2-penalized UOT:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\min_t \gamma \mathbf{c}^T t
+ 0.5 * \|H_r \mathbf{t} - \mathbf{a}\|_2^2\\s.t.
H_c \mathbf{t} = \mathbf{b}\\ \mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}\)</span> is the flattened version of the cost matrix <span class="math notranslate nohighlight">\(C\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gamma = 1/\lambda\)</span> is the l2-regularization parameter</p></li>
<li><p><span class="math notranslate nohighlight">\(H_r\)</span> is a matrix that computes the sum along the rows of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(H_c\)</span> is a matrix that computes the sum along the columns of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport plan <span class="math notranslate nohighlight">\(T\)</span></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>a</strong> (<em>np.ndarray</em><em> (</em><em>dim_a</em><em>,</em><em>)</em>) – Histogram of dimension dim_a</p></li>
<li><p><strong>b</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>,</em><em>)</em>) – Histogram of dimension dim_b</p></li>
<li><p><strong>C</strong> (<em>np.ndarray</em><em>, </em><em>shape</em><em> (</em><em>dim_a</em><em>, </em><em>dim_b</em><em>)</em>) – Cost matrix</p></li>
<li><p><strong>reg</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a><em> (</em><em>optional</em><em>)</em>) – l2-regularization coefficient</p></li>
<li><p><strong>itmax</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><em>)</em>) – Maximum number of iteration</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>t</strong> (<em>np.ndarray (dim_a*dim_b, )</em>) – Flattened vector of the (unregularized) optimal transport matrix</p></li>
<li><p><strong>t_list</strong> (<em>list</em>) – List of all the optimal transport vectors of the regularization path</p></li>
<li><p><strong>gamma_list</strong> (<em>list</em>) – List of the regularization parameters in the path</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">ot</span>
<span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="gp">>>> </span><span class="n">n</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">xs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">xt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">5.</span><span class="p">,</span> <span class="mf">6.</span><span class="p">,</span> <span class="mf">7.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">dist</span><span class="p">(</span><span class="n">xs</span><span class="p">,</span> <span class="n">xt</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">/=</span> <span class="n">C</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">semi_relaxed_path</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="mf">1e-4</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">t</span>
<span class="go">array([1.99980556e-01, 0.00000000e+00, 0.00000000e+00, 1.94444444e-05,</span>
<span class="go"> 4.99980556e-01, 0.00000000e+00, 0.00000000e+00, 1.94444444e-05,</span>
<span class="go"> 3.00000000e-01])</span>
</pre></div>
</div>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id10" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<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.regpath.</span></span><span class="sig-name descname"><span class="pre">complement_schur</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">M_current</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">d</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">id_pop</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#complement_schur"><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>This function computes the inverse of the design matrix in the regularization path using the Schur complement. Two cases may arise:</p>
<p>Case 1: one variable is added to the active set</p>
<div class="math notranslate nohighlight">
\[\begin{split}M_{k+1}^{-1} =
\begin{bmatrix}
M_{k}^{-1} + s^{-1} M_{k}^{-1} \mathbf{b} \mathbf{b}^T M_{k}^{-1} \
& - M_{k}^{-1} \mathbf{b} s^{-1} \\
- s^{-1} \mathbf{b}^T M_{k}^{-1} & s^{-1}
\end{bmatrix}\end{split}\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(M_k^{-1}\)</span> is the inverse of the design matrix <span class="math notranslate nohighlight">\(H_A^tH_A\)</span> of the previous iteration</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{b}\)</span> is the last column of <span class="math notranslate nohighlight">\(M_{k}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(s\)</span> is the Schur complement, given by <span class="math notranslate nohighlight">\(s = \mathbf{d} - \mathbf{b}^T M_{k}^{-1} \mathbf{b}\)</span></p></li>
</ul>
<p>Case 2: one variable is removed from the active set.</p>
<div class="math notranslate nohighlight">
\[M_{k+1}^{-1} = M^{-1}_{k \backslash q} -
\frac{r_{-q,q} r^{T}_{-q,q}}{r_{q,q}}\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(q\)</span> is the index of column and row to delete</p></li>
<li><p><span class="math notranslate nohighlight">\(M^{-1}_{k \backslash q}\)</span> is the previous inverse matrix deprived of the <span class="math notranslate nohighlight">\(q\)</span> th column and <span class="math notranslate nohighlight">\(q\)</span> th row</p></li>
<li><p><span class="math notranslate nohighlight">\(r_{-q,q}\)</span> is the <span class="math notranslate nohighlight">\(q\)</span> th column of <span class="math notranslate nohighlight">\(M^{-1}_{k}\)</span> without the <span class="math notranslate nohighlight">\(q\)</span> th element</p></li>
<li><p><span class="math notranslate nohighlight">\(r_{q, q}\)</span> is the element of <span class="math notranslate nohighlight">\(q\)</span> th column and <span class="math notranslate nohighlight">\(q\)</span> th row in <span class="math notranslate nohighlight">\(M^{-1}_{k}\)</span></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>M_current</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>-1</em><em>, </em><em>size</em><em>(</em><em>A</em><em>)</em><em>-1</em><em>)</em>) – Inverse matrix of <span class="math notranslate nohighlight">\(H_A^tH_A\)</span> at the previous iteration, with size(A) the size of the active set</p></li>
<li><p><strong>b</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>-1</em><em>, </em><em>)</em>) – None for case 2 (removal), last column of <span class="math notranslate nohighlight">\(M_{k}\)</span> for case 1 (addition)</p></li>
<li><p><strong>d</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – should be equal to 2 when UOT and 1 for the semi-relaxed OT</p></li>
<li><p><strong>id_pop</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a>) – Index of the variable to be removed, equal to -1
if no variable is deleted at the current iteration</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>M</strong> – Inverse matrix of <span class="math notranslate nohighlight">\(H_A^tH_A\)</span> of the current iteration</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>ndarray, shape (size(A), size(A))</p>
</dd>
</dl>
<p class="rubric">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id11" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id12">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">compute_next_removal</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">phi</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delta</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">current_gamma</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#compute_next_removal"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id12" title="Link to this definition"></a></dt>
<dd><p>This function computes the next gamma value if a variable
is removed at the next iteration of the regularization path.</p>
<p>We look for the largest value of the regularization parameter such that
an element of the current solution vanishes</p>
<div class="math notranslate nohighlight">
\[\max_{j \in A} \frac{\phi_j}{\delta_j}\]</div>
<p>where :</p>
<ul class="simple">
<li><p>A is the current active set</p></li>
<li><p><span class="math notranslate nohighlight">\(\phi_j\)</span> is the <span class="math notranslate nohighlight">\(j\)</span> th element of the intercept of the current solution</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta_j\)</span> is the <span class="math notranslate nohighlight">\(j\)</span> th element of the slope of the current solution</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>phi</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Intercept of the solution at the current iteration</p></li>
<li><p><strong>delta</strong> (<em>ndarray</em><em>, </em><em>shape</em><em> (</em><em>size</em><em>(</em><em>A</em><em>)</em><em>, </em><em>)</em>) – Slope of the solution at the current iteration</p></li>
<li><p><strong>current_gamma</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – Value of the regularization parameter at the beginning of the current iteration</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>next_removal_gamma</strong> (<em>float</em>) – Gamma value if a variable is removed at the next iteration</p></li>
<li><p><strong>next_removal_index</strong> (<em>int</em>) – Index of the variable to be removed at the next iteration</p></li>
</ul>
</p>
</dd>
</dl>
<p class="rubric" id="id13">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id14" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id15">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">compute_transport_plan</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gamma</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">gamma_list</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Pi_list</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#compute_transport_plan"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id15" title="Link to this definition"></a></dt>
<dd><p>Given the regularization path, this function computes the transport
plan for any value of gamma thanks to the piecewise linearity of the path.</p>
<div class="math notranslate nohighlight">
\[t(\gamma) = \phi(\gamma) - \gamma \delta(\gamma)\]</div>
<p>where:</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\gamma\)</span> is the regularization parameter</p></li>
<li><p><span class="math notranslate nohighlight">\(\phi(\gamma)\)</span> is the corresponding intercept</p></li>
<li><p><span class="math notranslate nohighlight">\(\delta(\gamma)\)</span> is the corresponding slope</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport matrix</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>gamma</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#float" title="(in Python v3.15)"><em>float</em></a>) – Regularization coefficient</p></li>
<li><p><strong>gamma_list</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – List of regularization parameters of the regularization path</p></li>
<li><p><strong>Pi_list</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – List of all the solutions of the regularization path</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>t</strong> – Vectorization of the transport plan corresponding to the given value
of gamma</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>np.ndarray (dim_a*dim_b, )</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">ot</span>
<span class="gp">>>> </span><span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="gp">>>> </span><span class="n">n</span> <span class="o">=</span> <span class="mi">3</span>
<span class="gp">>>> </span><span class="n">xs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.</span><span class="p">,</span> <span class="mf">2.</span><span class="p">,</span> <span class="mf">3.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">xt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">5.</span><span class="p">,</span> <span class="mf">6.</span><span class="p">,</span> <span class="mf">7.</span><span class="p">])</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="n">n</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">dist</span><span class="p">(</span><span class="n">xs</span><span class="p">,</span> <span class="n">xt</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">C</span> <span class="o">/=</span> <span class="n">C</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">t</span><span class="p">,</span> <span class="n">pi_list</span><span class="p">,</span> <span class="n">g_list</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">regularization_path</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">C</span><span class="p">,</span> <span class="n">reg</span><span class="o">=</span><span class="mf">1e-4</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">gamma</span> <span class="o">=</span> <span class="mi">1</span>
<span class="gp">>>> </span><span class="n">t2</span> <span class="o">=</span> <span class="n">ot</span><span class="o">.</span><span class="n">regpath</span><span class="o">.</span><span class="n">compute_transport_plan</span><span class="p">(</span><span class="n">gamma</span><span class="p">,</span> <span class="n">g_list</span><span class="p">,</span> <span class="n">pi_list</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">t2</span>
<span class="go">array([0. , 0. , 0. , 0.19722222, 0.05555556,</span>
<span class="go"> 0. , 0. , 0.24722222, 0. ])</span>
</pre></div>
</div>
<p class="rubric" id="id16">References</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="id17" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span>41<span class="fn-bracket">]</span></span>
<p>Chapel, L., Flamary, R., Wu, H., Févotte, C., and Gasso, G. (2021).
Unbalanced optimal transport through non-negative penalized
linear regression. NeurIPS.</p>
</aside>
</aside>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id18">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">construct_augmented_H</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">active_index</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Hc</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">HrHr</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#construct_augmented_H"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id18" title="Link to this definition"></a></dt>
<dd><p>This function constructs an augmented matrix for the first iteration
of the semi-relaxed regularization path</p>
<div class="math notranslate nohighlight">
\[\begin{split}\text{Augmented}_H =
\begin{bmatrix}
0 & H_{c A} \\
H_{c A}^T & H_{r A}^T H_{r A}
\end{bmatrix}\end{split}\]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(H_{r A}\)</span> is the sub-matrix constructed by the columns of <span class="math notranslate nohighlight">\(H_r\)</span> whose indices belong to the active set A</p></li>
<li><p><span class="math notranslate nohighlight">\(H_{c A}\)</span> is the sub-matrix constructed by the columns of <span class="math notranslate nohighlight">\(H_c\)</span> whose indices belong to the active set A</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>active_index</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/stdtypes.html#list" title="(in Python v3.15)"><em>list</em></a>) – Indices of the active variables</p></li>
<li><p><strong>m</strong> (<a class="reference external" href="https://docs.python.org/3/builtins/functions.html#int" title="(in Python v3.15)"><em>int</em></a>) – Length of the target distribution</p></li>
<li><p><strong>Hc</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix that computes the sum along the columns of the transport plan <span class="math notranslate nohighlight">\(T\)</span></p></li>
<li><p><strong>HrHr</strong> (<em>np.ndarray</em><em> (</em><em>dim_a * dim_b</em><em>, </em><em>dim_a * dim_b</em><em>)</em>) – Matrix product of <span class="math notranslate nohighlight">\(H_r^T H_r\)</span></p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><strong>H_augmented</strong> – Augmented matrix for the first iteration of the semi-relaxed
regularization path</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>np.ndarray (dim_b + size(A), dim_b + size(A))</p>
</dd>
</dl>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="id19">
<span class="sig-prename descclassname"><span class="pre">ot.regpath.</span></span><span class="sig-name descname"><span class="pre">fully_relaxed_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">C</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">array</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.0001</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">itmax</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">50000</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/ot/regpath.html#fully_relaxed_path"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#id19" title="Link to this definition"></a></dt>
<dd><p>This function gives the regularization path of l2-penalized UOT problem</p>
<p>The problem to optimize is the Lasso reformulation of the l2-penalized UOT:</p>
<div class="math notranslate nohighlight">
\[ \begin{align}\begin{aligned}\min_t \gamma \mathbf{c}^T \mathbf{t}
+ 0.5 * \|{H} \mathbf{t} - \mathbf{y}\|_2^2\\s.t.
\mathbf{t} \geq 0\end{aligned}\end{align} \]</div>
<p>where :</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\mathbf{c}\)</span> is the flattened version of the cost matrix <span class="math notranslate nohighlight">\({C}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\gamma = 1/\lambda\)</span> is the l2-regularization coefficient</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{y}\)</span> is the concatenation of vectors <span class="math notranslate nohighlight">\(\mathbf{a}\)</span> and <span class="math notranslate nohighlight">\(\mathbf{b}\)</span>, defined as <span class="math notranslate nohighlight">\(\mathbf{y}^T = [\mathbf{a}^T \mathbf{b}^T]\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\({H}\)</span> is a design matrix, see <a class="reference internal" href="ot.unbalanced.html#references-regpath"><span class="std std-ref">[41]</span></a> for the design of <span class="math notranslate nohighlight">\({H}\)</span>. The matrix product <span class="math notranslate nohighlight">\(H\mathbf{t}\)</span> computes both the source marginal and the target marginals.</p></li>
<li><p><span class="math notranslate nohighlight">\(\mathbf{t}\)</span> is the flattened version of the transport matrix</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>a</strong> (<em>np.ndarray</em><em> (</em><em>dim_a</em><em>,</em><em>)</em>) – Histogram of dimension dim_a</p></li>
<li><p><strong>b</strong> (<em>np.ndarray</em><em> (</em><em>dim_b</em><em>,</em><em>)</em>) – Histogram of dimension dim_b</p></li>
<li><p><strong>C</strong> (<em>np.ndarray</em><em>, </em><em>shape</em><em> (</em><em>dim_a</em><em>, </em><em>dim_b</em><em>)</em>) – Cost matrix</p></li>