1212import ot
1313
1414
15+ ##############################################################################
16+ # Generate data
17+ ##############################################################################
18+
1519#%% parameters
1620
1721n = 100 # nb bins
2731M = ot .dist (x .reshape ((n , 1 )), x .reshape ((n , 1 )))
2832M /= M .max ()
2933
34+ ##############################################################################
35+ # Solve EMD
36+ ##############################################################################
37+
3038#%% EMD
3139
3240G0 = ot .emd (a , b , M )
3341
3442pl .figure (3 , figsize = (5 , 5 ))
3543ot .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):
5264pl .figure (3 )
5365ot .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):
7086pl .figure (4 , figsize = (5 , 5 ))
7187ot .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
7695def f (G ):
7796 return 0.5 * np .sum (G ** 2 )
0 commit comments