summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKilian Fatras <kilianfatras@dhcp-206-12-52-229.eduroam.wireless.ubc.ca>2018-06-25 11:03:44 -0700
committerKilian Fatras <kilianfatras@dhcp-206-12-52-229.eduroam.wireless.ubc.ca>2018-06-25 11:03:44 -0700
commit9fecd51c583704e02d3faaef722f0dee52f42359 (patch)
treef35d7525f6f48f78f6b17df6309f91cc84d5a4f5
parente8cf3cc343c934b7c49d303186cdf226204813b3 (diff)
fix math operator and log bugs
-rw-r--r--examples/plot_stochastic.py18
-rw-r--r--ot/stochastic.py15
2 files changed, 22 insertions, 11 deletions
diff --git a/examples/plot_stochastic.py b/examples/plot_stochastic.py
index 6274b4c..b9375d4 100644
--- a/examples/plot_stochastic.py
+++ b/examples/plot_stochastic.py
@@ -15,6 +15,7 @@ algorithms for descrete and semicontinous measures from the POT library.
import matplotlib.pylab as pl
import numpy as np
import ot
+import ot.plot
#############################################################################
@@ -88,9 +89,9 @@ M = ot.dist(X_source, Y_target)
# results.
method = "ASGD"
-asgd_pi, log = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method,
- numItermax, log)
-print(log['alpha'], log['beta'])
+asgd_pi, log_asgd = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method,
+ numItermax, log=log)
+print(log_asgd['alpha'], log_asgd['beta'])
print(asgd_pi)
#############################################################################
@@ -166,15 +167,16 @@ M = ot.dist(X_source, Y_target)
#############################################################################
#
-# Call the "SGD" dual method to find the transportation matrix in the semicontinous
-# case
+# Call the "SGD" dual method to find the transportation matrix in the
+# semicontinous case
# ---------------------------------------------
#
# Call ot.solve_dual_entropic and plot the results.
-sgd_dual_pi, log = ot.stochastic.solve_dual_entropic(a, b, M, reg, batch_size,
- numItermax, lr, log)
-print(log['alpha'], log['beta'])
+sgd_dual_pi, log_sgd = ot.stochastic.solve_dual_entropic(a, b, M, reg,
+ batch_size, numItermax,
+ lr, log=log)
+print(log_sgd['alpha'], log_sgd['beta'])
print(sgd_dual_pi)
#############################################################################
diff --git a/ot/stochastic.py b/ot/stochastic.py
index f4d4c7d..5e8206e 100644
--- a/ot/stochastic.py
+++ b/ot/stochastic.py
@@ -16,8 +16,9 @@ def coordinate_grad_semi_dual(b, M, reg, beta, i):
distributions for (i, :)
The function computes the gradient of the semi dual problem:
+
.. math::
- \W_varepsilon(a, b) = \max_\v \sum_i (\sum_j v_j * b_j
+ \W_\varepsilon(a, b) = \max_\v \sum_i (\sum_j v_j * b_j
- \reg log(\sum_j exp((v_j - M_{i,j})/reg) * b_j)) * a_i
where :
@@ -89,6 +90,7 @@ def sag_entropic_transport(a, b, M, reg, numItermax=10000, lr=None):
optimal transport max problem
The function solves the following optimization problem:
+
.. math::
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
s.t. \gamma 1 = a
@@ -175,6 +177,7 @@ def averaged_sgd_entropic_transport(a, b, M, reg, numItermax=300000, lr=None):
optimal transport max problem
The function solves the following optimization problem:
+
.. math::
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
s.t. \gamma 1 = a
@@ -258,6 +261,7 @@ def c_transform_entropic(b, M, reg, beta):
The function computes the c_transform of a dual variable from the other
dual variable:
+
.. math::
u = v^{c,reg} = -reg \sum_j exp((v - M)/reg) b_j
@@ -331,6 +335,7 @@ def solve_semi_dual_entropic(a, b, M, reg, method, numItermax=10000, lr=None,
measures optimal transport max problem
The function solves the following optimization problem:
+
.. math::
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
s.t. \gamma 1 = a
@@ -436,7 +441,8 @@ def batch_grad_dual_alpha(M, reg, alpha, beta, batch_size, batch_alpha,
Computes the partial gradient of F_\W_varepsilon
Compute the partial gradient of the dual problem:
- ..Math:
+
+ ..math:
\forall i in batch_alpha,
grad_alpha_i = 1 * batch_size -
sum_{j in batch_beta} exp((alpha_i + beta_j - M_{i,j})/reg)
@@ -518,7 +524,8 @@ def batch_grad_dual_beta(M, reg, alpha, beta, batch_size, batch_alpha,
Computes the partial gradient of F_\W_varepsilon
Compute the partial gradient of the dual problem:
- ..Math:
+
+ ..math:
\forall j in batch_beta,
grad_beta_j = 1 * batch_size -
sum_{i in batch_alpha} exp((alpha_i + beta_j - M_{i,j})/reg)
@@ -602,6 +609,7 @@ def sgd_entropic_regularization(M, reg, batch_size, numItermax, lr,
optimal transport dual problem
The function solves the following optimization problem:
+
.. math::
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
s.t. \gamma 1 = a
@@ -709,6 +717,7 @@ def solve_dual_entropic(a, b, M, reg, batch_size, numItermax=10000, lr=1,
optimal transport dual problem
The function solves the following optimization problem:
+
.. math::
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
s.t. \gamma 1 = a