Skip to content

Commit 3547344

Browse files
committed
exples +rst
1 parent 164dc24 commit 3547344

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

examples/plot_OT_1D.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import ot
1616
from ot.datasets import get_1D_gauss as gauss
1717

18+
##############################################################################
19+
# Generate data
20+
##############################################################################
21+
1822
#%% parameters
1923

2024
n = 100 # nb bins
@@ -30,6 +34,11 @@
3034
M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
3135
M /= M.max()
3236

37+
38+
##############################################################################
39+
# Plot distributions and loss matrix
40+
##############################################################################
41+
3342
#%% plot the distributions
3443

3544
pl.figure(1, figsize=(6.4, 3))
@@ -42,13 +51,21 @@
4251
pl.figure(2, figsize=(5, 5))
4352
ot.plot.plot1D_mat(a, b, M, 'Cost matrix M')
4453

54+
##############################################################################
55+
# Solve EMD
56+
##############################################################################
57+
4558
#%% EMD
4659

4760
G0 = ot.emd(a, b, M)
4861

4962
pl.figure(3, figsize=(5, 5))
5063
ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0')
5164

65+
##############################################################################
66+
# Solve Sinkhorn
67+
##############################################################################
68+
5269
#%% Sinkhorn
5370

5471
lambd = 1e-3

examples/plot_optim_OTreg.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import ot
1313

1414

15+
##############################################################################
16+
# Generate data
17+
##############################################################################
18+
1519
#%% parameters
1620

1721
n = 100 # nb bins
@@ -27,13 +31,21 @@
2731
M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
2832
M /= M.max()
2933

34+
##############################################################################
35+
# Solve EMD
36+
##############################################################################
37+
3038
#%% EMD
3139

3240
G0 = ot.emd(a, b, M)
3341

3442
pl.figure(3, figsize=(5, 5))
3543
ot.plot.plot1D_mat(a, b, G0, 'OT matrix G0')
3644

45+
##############################################################################
46+
# Solve EMD with Frobenius norm regularization
47+
##############################################################################
48+
3749
#%% Example with Frobenius norm regularization
3850

3951

@@ -52,6 +64,10 @@ def df(G):
5264
pl.figure(3)
5365
ot.plot.plot1D_mat(a, b, Gl2, 'OT matrix Frob. reg')
5466

67+
##############################################################################
68+
# Solve EMD with entropic regularization
69+
##############################################################################
70+
5571
#%% Example with entropic regularization
5672

5773

@@ -70,8 +86,11 @@ def df(G):
7086
pl.figure(4, figsize=(5, 5))
7187
ot.plot.plot1D_mat(a, b, Ge, 'OT matrix Entrop. reg')
7288

73-
#%% Example with Frobenius norm + entropic regularization with gcg
89+
##############################################################################
90+
# Solve EMD with Frobenius norm + entropic regularization
91+
##############################################################################
7492

93+
#%% Example with Frobenius norm + entropic regularization with gcg
7594

7695
def f(G):
7796
return 0.5 * np.sum(G**2)

0 commit comments

Comments
 (0)