|
16 | 16 |
|
17 | 17 | def sinkhorn(a, b, M, reg, method='sinkhorn', numItermax=1000,
|
18 | 18 | stopThr=1e-9, verbose=False, log=False, **kwargs):
|
19 |
| - u""" |
| 19 | + r""" |
20 | 20 | Solve the entropic regularization optimal transport problem and return the OT matrix
|
21 | 21 |
|
22 | 22 | The function solves the following optimization problem:
|
@@ -73,12 +73,12 @@ def sinkhorn(a, b, M, reg, method='sinkhorn', numItermax=1000,
|
73 | 73 | --------
|
74 | 74 |
|
75 | 75 | >>> import ot
|
76 |
| - >>> a=[.5,.5] |
77 |
| - >>> b=[.5,.5] |
78 |
| - >>> M=[[0.,1.],[1.,0.]] |
79 |
| - >>> ot.sinkhorn(a,b,M,1) |
80 |
| - array([[ 0.36552929, 0.13447071], |
81 |
| - [ 0.13447071, 0.36552929]]) |
| 76 | + >>> a=[.5, .5] |
| 77 | + >>> b=[.5, .5] |
| 78 | + >>> M=[[0., 1.], [1., 0.]] |
| 79 | + >>> ot.sinkhorn(a, b, M, 1) |
| 80 | + array([[0.36552929, 0.13447071], |
| 81 | + [0.13447071, 0.36552929]]) |
82 | 82 |
|
83 | 83 |
|
84 | 84 | References
|
@@ -131,7 +131,7 @@ def sink():
|
131 | 131 |
|
132 | 132 | def sinkhorn2(a, b, M, reg, method='sinkhorn', numItermax=1000,
|
133 | 133 | stopThr=1e-9, verbose=False, log=False, **kwargs):
|
134 |
| - u""" |
| 134 | + r""" |
135 | 135 | Solve the entropic regularization optimal transport problem and return the loss
|
136 | 136 |
|
137 | 137 | The function solves the following optimization problem:
|
@@ -188,11 +188,11 @@ def sinkhorn2(a, b, M, reg, method='sinkhorn', numItermax=1000,
|
188 | 188 | --------
|
189 | 189 |
|
190 | 190 | >>> import ot
|
191 |
| - >>> a=[.5,.5] |
192 |
| - >>> b=[.5,.5] |
193 |
| - >>> M=[[0.,1.],[1.,0.]] |
194 |
| - >>> ot.sinkhorn2(a,b,M,1) |
195 |
| - array([ 0.26894142]) |
| 191 | + >>> a=[.5, .5] |
| 192 | + >>> b=[.5, .5] |
| 193 | + >>> M=[[0., 1.], [1., 0.]] |
| 194 | + >>> ot.sinkhorn2(a, b, M, 1) |
| 195 | + array([0.26894142]) |
196 | 196 |
|
197 | 197 |
|
198 | 198 |
|
@@ -248,7 +248,7 @@ def sink():
|
248 | 248 |
|
249 | 249 | def sinkhorn_knopp(a, b, M, reg, numItermax=1000,
|
250 | 250 | stopThr=1e-9, verbose=False, log=False, **kwargs):
|
251 |
| - """ |
| 251 | + r""" |
252 | 252 | Solve the entropic regularization optimal transport problem and return the OT matrix
|
253 | 253 |
|
254 | 254 | The function solves the following optimization problem:
|
@@ -302,12 +302,12 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000,
|
302 | 302 | --------
|
303 | 303 |
|
304 | 304 | >>> import ot
|
305 |
| - >>> a=[.5,.5] |
306 |
| - >>> b=[.5,.5] |
307 |
| - >>> M=[[0.,1.],[1.,0.]] |
308 |
| - >>> ot.sinkhorn(a,b,M,1) |
309 |
| - array([[ 0.36552929, 0.13447071], |
310 |
| - [ 0.13447071, 0.36552929]]) |
| 305 | + >>> a=[.5, .5] |
| 306 | + >>> b=[.5, .5] |
| 307 | + >>> M=[[0., 1.], [1., 0.]] |
| 308 | + >>> ot.sinkhorn(a, b, M, 1) |
| 309 | + array([[0.36552929, 0.13447071], |
| 310 | + [0.13447071, 0.36552929]]) |
311 | 311 |
|
312 | 312 |
|
313 | 313 | References
|
@@ -422,7 +422,7 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000,
|
422 | 422 |
|
423 | 423 |
|
424 | 424 | def greenkhorn(a, b, M, reg, numItermax=10000, stopThr=1e-9, verbose=False, log=False):
|
425 |
| - """ |
| 425 | + r""" |
426 | 426 | Solve the entropic regularization optimal transport problem and return the OT matrix
|
427 | 427 |
|
428 | 428 | The algorithm used is based on the paper
|
@@ -481,12 +481,12 @@ def greenkhorn(a, b, M, reg, numItermax=10000, stopThr=1e-9, verbose=False, log=
|
481 | 481 | --------
|
482 | 482 |
|
483 | 483 | >>> import ot
|
484 |
| - >>> a=[.5,.5] |
485 |
| - >>> b=[.5,.5] |
486 |
| - >>> M=[[0.,1.],[1.,0.]] |
487 |
| - >>> ot.bregman.greenkhorn(a,b,M,1) |
488 |
| - array([[ 0.36552929, 0.13447071], |
489 |
| - [ 0.13447071, 0.36552929]]) |
| 484 | + >>> a=[.5, .5] |
| 485 | + >>> b=[.5, .5] |
| 486 | + >>> M=[[0., 1.], [1., 0.]] |
| 487 | + >>> ot.bregman.greenkhorn(a, b, M, 1) |
| 488 | + array([[0.36552929, 0.13447071], |
| 489 | + [0.13447071, 0.36552929]]) |
490 | 490 |
|
491 | 491 |
|
492 | 492 | References
|
@@ -576,7 +576,7 @@ def greenkhorn(a, b, M, reg, numItermax=10000, stopThr=1e-9, verbose=False, log=
|
576 | 576 |
|
577 | 577 | def sinkhorn_stabilized(a, b, M, reg, numItermax=1000, tau=1e3, stopThr=1e-9,
|
578 | 578 | warmstart=None, verbose=False, print_period=20, log=False, **kwargs):
|
579 |
| - """ |
| 579 | + r""" |
580 | 580 | Solve the entropic regularization OT problem with log stabilization
|
581 | 581 |
|
582 | 582 | The function solves the following optimization problem:
|
@@ -639,8 +639,8 @@ def sinkhorn_stabilized(a, b, M, reg, numItermax=1000, tau=1e3, stopThr=1e-9,
|
639 | 639 | >>> b=[.5,.5]
|
640 | 640 | >>> M=[[0.,1.],[1.,0.]]
|
641 | 641 | >>> ot.bregman.sinkhorn_stabilized(a,b,M,1)
|
642 |
| - array([[ 0.36552929, 0.13447071], |
643 |
| - [ 0.13447071, 0.36552929]]) |
| 642 | + array([[0.36552929, 0.13447071], |
| 643 | + [0.13447071, 0.36552929]]) |
644 | 644 |
|
645 | 645 |
|
646 | 646 | References
|
@@ -796,7 +796,7 @@ def get_Gamma(alpha, beta, u, v):
|
796 | 796 |
|
797 | 797 | def sinkhorn_epsilon_scaling(a, b, M, reg, numItermax=100, epsilon0=1e4, numInnerItermax=100,
|
798 | 798 | tau=1e3, stopThr=1e-9, warmstart=None, verbose=False, print_period=10, log=False, **kwargs):
|
799 |
| - """ |
| 799 | + r""" |
800 | 800 | Solve the entropic regularization optimal transport problem with log
|
801 | 801 | stabilization and epsilon scaling.
|
802 | 802 |
|
@@ -862,12 +862,12 @@ def sinkhorn_epsilon_scaling(a, b, M, reg, numItermax=100, epsilon0=1e4, numInne
|
862 | 862 | --------
|
863 | 863 |
|
864 | 864 | >>> import ot
|
865 |
| - >>> a=[.5,.5] |
866 |
| - >>> b=[.5,.5] |
867 |
| - >>> M=[[0.,1.],[1.,0.]] |
868 |
| - >>> ot.bregman.sinkhorn_epsilon_scaling(a,b,M,1) |
869 |
| - array([[ 0.36552929, 0.13447071], |
870 |
| - [ 0.13447071, 0.36552929]]) |
| 865 | + >>> a=[.5, .5] |
| 866 | + >>> b=[.5, .5] |
| 867 | + >>> M=[[0., 1.], [1., 0.]] |
| 868 | + >>> ot.bregman.sinkhorn_epsilon_scaling(a, b, M, 1) |
| 869 | + array([[0.36552929, 0.13447071], |
| 870 | + [0.13447071, 0.36552929]]) |
871 | 871 |
|
872 | 872 |
|
873 | 873 | References
|
@@ -989,7 +989,7 @@ def projC(gamma, q):
|
989 | 989 |
|
990 | 990 | def barycenter(A, M, reg, weights=None, numItermax=1000,
|
991 | 991 | stopThr=1e-4, verbose=False, log=False):
|
992 |
| - """Compute the entropic regularized wasserstein barycenter of distributions A |
| 992 | + r"""Compute the entropic regularized wasserstein barycenter of distributions A |
993 | 993 |
|
994 | 994 | The function solves the following optimization problem:
|
995 | 995 |
|
@@ -1084,7 +1084,7 @@ def barycenter(A, M, reg, weights=None, numItermax=1000,
|
1084 | 1084 |
|
1085 | 1085 |
|
1086 | 1086 | def convolutional_barycenter2d(A, reg, weights=None, numItermax=10000, stopThr=1e-9, stabThr=1e-30, verbose=False, log=False):
|
1087 |
| - """Compute the entropic regularized wasserstein barycenter of distributions A |
| 1087 | + r"""Compute the entropic regularized wasserstein barycenter of distributions A |
1088 | 1088 | where A is a collection of 2D images.
|
1089 | 1089 |
|
1090 | 1090 | The function solves the following optimization problem:
|
@@ -1195,7 +1195,7 @@ def K(x):
|
1195 | 1195 |
|
1196 | 1196 | def unmix(a, D, M, M0, h0, reg, reg0, alpha, numItermax=1000,
|
1197 | 1197 | stopThr=1e-3, verbose=False, log=False):
|
1198 |
| - """ |
| 1198 | + r""" |
1199 | 1199 | Compute the unmixing of an observation with a given dictionary using Wasserstein distance
|
1200 | 1200 |
|
1201 | 1201 | The function solve the following optimization problem:
|
@@ -1302,7 +1302,7 @@ def unmix(a, D, M, M0, h0, reg, reg0, alpha, numItermax=1000,
|
1302 | 1302 |
|
1303 | 1303 |
|
1304 | 1304 | def empirical_sinkhorn(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', numIterMax=10000, stopThr=1e-9, verbose=False, log=False, **kwargs):
|
1305 |
| - ''' |
| 1305 | + r''' |
1306 | 1306 | Solve the entropic regularization optimal transport problem and return the
|
1307 | 1307 | OT matrix from empirical data
|
1308 | 1308 |
|
@@ -1360,10 +1360,9 @@ def empirical_sinkhorn(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', numI
|
1360 | 1360 | >>> reg = 0.1
|
1361 | 1361 | >>> X_s = np.reshape(np.arange(n_s), (n_s, 1))
|
1362 | 1362 | >>> X_t = np.reshape(np.arange(0, n_t), (n_t, 1))
|
1363 |
| - >>> emp_sinkhorn = empirical_sinkhorn(X_s, X_t, reg, verbose=False) |
1364 |
| - >>> print(emp_sinkhorn) |
1365 |
| - >>> [[4.99977301e-01 2.26989344e-05] |
1366 |
| - [2.26989344e-05 4.99977301e-01]] |
| 1363 | + >>> empirical_sinkhorn(X_s, X_t, reg, verbose=False) # doctest: +NORMALIZE_WHITESPACE |
| 1364 | + array([[4.99977301e-01, 2.26989344e-05], |
| 1365 | + [2.26989344e-05, 4.99977301e-01]]) |
1367 | 1366 |
|
1368 | 1367 |
|
1369 | 1368 | References
|
@@ -1392,7 +1391,7 @@ def empirical_sinkhorn(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', numI
|
1392 | 1391 |
|
1393 | 1392 |
|
1394 | 1393 | def empirical_sinkhorn2(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', numIterMax=10000, stopThr=1e-9, verbose=False, log=False, **kwargs):
|
1395 |
| - ''' |
| 1394 | + r''' |
1396 | 1395 | Solve the entropic regularization optimal transport problem from empirical
|
1397 | 1396 | data and return the OT loss
|
1398 | 1397 |
|
@@ -1451,9 +1450,8 @@ def empirical_sinkhorn2(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', num
|
1451 | 1450 | >>> reg = 0.1
|
1452 | 1451 | >>> X_s = np.reshape(np.arange(n_s), (n_s, 1))
|
1453 | 1452 | >>> X_t = np.reshape(np.arange(0, n_t), (n_t, 1))
|
1454 |
| - >>> loss_sinkhorn = empirical_sinkhorn2(X_s, X_t, reg, verbose=False) |
1455 |
| - >>> print(loss_sinkhorn) |
1456 |
| - >>> [4.53978687e-05] |
| 1453 | + >>> empirical_sinkhorn2(X_s, X_t, reg, verbose=False) |
| 1454 | + array([4.53978687e-05]) |
1457 | 1455 |
|
1458 | 1456 |
|
1459 | 1457 | References
|
@@ -1482,7 +1480,7 @@ def empirical_sinkhorn2(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', num
|
1482 | 1480 |
|
1483 | 1481 |
|
1484 | 1482 | def empirical_sinkhorn_divergence(X_s, X_t, reg, a=None, b=None, metric='sqeuclidean', numIterMax=10000, stopThr=1e-9, verbose=False, log=False, **kwargs):
|
1485 |
| - ''' |
| 1483 | + r''' |
1486 | 1484 | Compute the sinkhorn divergence loss from empirical data
|
1487 | 1485 |
|
1488 | 1486 | The function solves the following optimization problems and return the
|
@@ -1560,9 +1558,8 @@ def empirical_sinkhorn_divergence(X_s, X_t, reg, a=None, b=None, metric='sqeucli
|
1560 | 1558 | >>> reg = 0.1
|
1561 | 1559 | >>> X_s = np.reshape(np.arange(n_s), (n_s, 1))
|
1562 | 1560 | >>> X_t = np.reshape(np.arange(0, n_t), (n_t, 1))
|
1563 |
| - >>> emp_sinkhorn_div = empirical_sinkhorn_divergence(X_s, X_t, reg) |
1564 |
| - >>> print(emp_sinkhorn_div) |
1565 |
| - >>> [2.99977435] |
| 1561 | + >>> empirical_sinkhorn_divergence(X_s, X_t, reg) # doctest: +ELLIPSIS |
| 1562 | + array([1.499...]) |
1566 | 1563 |
|
1567 | 1564 |
|
1568 | 1565 | References
|
|
0 commit comments