diff options
author | Rémi Flamary <remi.flamary@gmail.com> | 2016-10-28 15:24:32 +0200 |
---|---|---|
committer | Rémi Flamary <remi.flamary@gmail.com> | 2016-10-28 15:24:32 +0200 |
commit | 1dd1ed6db5dda760839aac7bba291a00fcae2126 (patch) | |
tree | b60f7b94128f7eaac5a69d8801a35b14ec348af1 /examples/demo_optim_OTreg.py | |
parent | 0d81de9909e8e9eb95858f0a043550b15898f172 (diff) |
new notebook
Diffstat (limited to 'examples/demo_optim_OTreg.py')
-rw-r--r-- | examples/demo_optim_OTreg.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/examples/demo_optim_OTreg.py b/examples/demo_optim_OTreg.py index 5e88bdb..5e19be5 100644 --- a/examples/demo_optim_OTreg.py +++ b/examples/demo_optim_OTreg.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -demo of Optimal transport for domain adaptation +Regularized OT with generic solver """ import numpy as np @@ -31,18 +31,26 @@ G0=ot.emd(a,b,M) pl.figure(3) ot.plot.plot1D_mat(a,b,G0,'OT matrix G0') -#%% exampel of regularization with Frobnisu norm +#%% Example with Frobenisu norm regularization + +def f(G): return 0.5*np.sum(G**2) +def df(G): return G -def f(G): - #return 0.5*np.sum(G**2) - return np.sum(G*np.log(G)) - -def df(G): -# return G - return np.log(G)+1 reg=1e-1 -Greg=ot.optim.cg(a,b,M,reg,f,df,verbose=True) +Gl2=ot.optim.cg(a,b,M,reg,f,df,verbose=True) + +pl.figure(3) +ot.plot.plot1D_mat(a,b,Gl2,'OT matrix Frob. reg') + +#%% Examlple with entropic regularization + +def f(G): return np.sum(G*np.log(G)) +def df(G): return np.log(G)+1 + +reg=1e-3 + +Ge=ot.optim.cg(a,b,M,reg,f,df,verbose=True) pl.figure(4) -ot.plot.plot1D_mat(a,b,Greg,'OT matrix G0')
\ No newline at end of file +ot.plot.plot1D_mat(a,b,Ge,'OT matrix Entrop. reg')
\ No newline at end of file |