Skip to content

Commit 9fecd51

Browse files
author
Kilian Fatras
committed
fix math operator and log bugs
1 parent e8cf3cc commit 9fecd51

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

examples/plot_stochastic.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import matplotlib.pylab as pl
1616
import numpy as np
1717
import ot
18+
import ot.plot
1819

1920

2021
#############################################################################
@@ -88,9 +89,9 @@
8889
# results.
8990

9091
method = "ASGD"
91-
asgd_pi, log = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method,
92-
numItermax, log)
93-
print(log['alpha'], log['beta'])
92+
asgd_pi, log_asgd = ot.stochastic.solve_semi_dual_entropic(a, b, M, reg, method,
93+
numItermax, log=log)
94+
print(log_asgd['alpha'], log_asgd['beta'])
9495
print(asgd_pi)
9596

9697
#############################################################################
@@ -166,15 +167,16 @@
166167

167168
#############################################################################
168169
#
169-
# Call the "SGD" dual method to find the transportation matrix in the semicontinous
170-
# case
170+
# Call the "SGD" dual method to find the transportation matrix in the
171+
# semicontinous case
171172
# ---------------------------------------------
172173
#
173174
# Call ot.solve_dual_entropic and plot the results.
174175

175-
sgd_dual_pi, log = ot.stochastic.solve_dual_entropic(a, b, M, reg, batch_size,
176-
numItermax, lr, log)
177-
print(log['alpha'], log['beta'])
176+
sgd_dual_pi, log_sgd = ot.stochastic.solve_dual_entropic(a, b, M, reg,
177+
batch_size, numItermax,
178+
lr, log=log)
179+
print(log_sgd['alpha'], log_sgd['beta'])
178180
print(sgd_dual_pi)
179181

180182
#############################################################################

ot/stochastic.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def coordinate_grad_semi_dual(b, M, reg, beta, i):
1616
distributions for (i, :)
1717
1818
The function computes the gradient of the semi dual problem:
19+
1920
.. math::
20-
\W_varepsilon(a, b) = \max_\v \sum_i (\sum_j v_j * b_j
21+
\W_\varepsilon(a, b) = \max_\v \sum_i (\sum_j v_j * b_j
2122
- \reg log(\sum_j exp((v_j - M_{i,j})/reg) * b_j)) * a_i
2223
2324
where :
@@ -89,6 +90,7 @@ def sag_entropic_transport(a, b, M, reg, numItermax=10000, lr=None):
8990
optimal transport max problem
9091
9192
The function solves the following optimization problem:
93+
9294
.. math::
9395
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
9496
s.t. \gamma 1 = a
@@ -175,6 +177,7 @@ def averaged_sgd_entropic_transport(a, b, M, reg, numItermax=300000, lr=None):
175177
optimal transport max problem
176178
177179
The function solves the following optimization problem:
180+
178181
.. math::
179182
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
180183
s.t. \gamma 1 = a
@@ -258,6 +261,7 @@ def c_transform_entropic(b, M, reg, beta):
258261
259262
The function computes the c_transform of a dual variable from the other
260263
dual variable:
264+
261265
.. math::
262266
u = v^{c,reg} = -reg \sum_j exp((v - M)/reg) b_j
263267
@@ -331,6 +335,7 @@ def solve_semi_dual_entropic(a, b, M, reg, method, numItermax=10000, lr=None,
331335
measures optimal transport max problem
332336
333337
The function solves the following optimization problem:
338+
334339
.. math::
335340
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
336341
s.t. \gamma 1 = a
@@ -436,7 +441,8 @@ def batch_grad_dual_alpha(M, reg, alpha, beta, batch_size, batch_alpha,
436441
Computes the partial gradient of F_\W_varepsilon
437442
438443
Compute the partial gradient of the dual problem:
439-
..Math:
444+
445+
..math:
440446
\forall i in batch_alpha,
441447
grad_alpha_i = 1 * batch_size -
442448
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,
518524
Computes the partial gradient of F_\W_varepsilon
519525
520526
Compute the partial gradient of the dual problem:
521-
..Math:
527+
528+
..math:
522529
\forall j in batch_beta,
523530
grad_beta_j = 1 * batch_size -
524531
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,
602609
optimal transport dual problem
603610
604611
The function solves the following optimization problem:
612+
605613
.. math::
606614
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
607615
s.t. \gamma 1 = a
@@ -709,6 +717,7 @@ def solve_dual_entropic(a, b, M, reg, batch_size, numItermax=10000, lr=1,
709717
optimal transport dual problem
710718
711719
The function solves the following optimization problem:
720+
712721
.. math::
713722
\gamma = arg\min_\gamma <\gamma,M>_F + reg\cdot\Omega(\gamma)
714723
s.t. \gamma 1 = a

0 commit comments

Comments
 (0)