Skip to content

Commit 345f094

Browse files
change BAPG names + improve doc
1 parent a0344ba commit 345f094

File tree

4 files changed

+109
-51
lines changed

4 files changed

+109
-51
lines changed

examples/gromov/plot_fgw_solvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import matplotlib.pylab as pl
4747
from ot.gromov import (fused_gromov_wasserstein,
4848
entropic_fused_gromov_wasserstein,
49-
entropic_BAPG_fused_gromov_wasserstein)
49+
BAPG_fused_gromov_wasserstein)
5050
import networkx
5151
from networkx.generators.community import stochastic_block_model as sbm
5252
from time import time
@@ -128,7 +128,7 @@
128128
# Alternated Bregman Projected Gradient algorithm with Kullback-Leibler as proximal operator
129129
print('Bregman Alternated Projected Gradient \n')
130130
start_bapg = time()
131-
T_bapg, log_bapg = entropic_BAPG_fused_gromov_wasserstein(
131+
T_bapg, log_bapg = BAPG_fused_gromov_wasserstein(
132132
M, C2, C3, h2, h3, 'square_loss', alpha=alpha, epsilon=1.,
133133
tol=1e-9, marginal_loss=True, verbose=True, log=True)
134134
end_bapg = time()

ot/gromov/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020

2121
from ._bregman import (entropic_gromov_wasserstein,
2222
entropic_gromov_wasserstein2,
23-
entropic_BAPG_gromov_wasserstein,
24-
entropic_BAPG_gromov_wasserstein2,
23+
BAPG_gromov_wasserstein,
24+
BAPG_gromov_wasserstein2,
2525
entropic_gromov_barycenters,
2626
entropic_fused_gromov_wasserstein,
2727
entropic_fused_gromov_wasserstein2,
28-
entropic_BAPG_fused_gromov_wasserstein,
29-
entropic_BAPG_fused_gromov_wasserstein2,
28+
BAPG_fused_gromov_wasserstein,
29+
BAPG_fused_gromov_wasserstein2,
3030
entropic_fused_gromov_barycenters)
3131

3232
from ._estimators import (GW_distance_estimation, pointwise_gromov_wasserstein,
@@ -53,10 +53,10 @@
5353
'gromov_wasserstein', 'gromov_wasserstein2', 'fused_gromov_wasserstein',
5454
'fused_gromov_wasserstein2', 'solve_gromov_linesearch', 'gromov_barycenters',
5555
'fgw_barycenters', 'entropic_gromov_wasserstein', 'entropic_gromov_wasserstein2',
56-
'entropic_BAPG_gromov_wasserstein', 'entropic_BAPG_gromov_wasserstein2',
56+
'BAPG_gromov_wasserstein', 'BAPG_gromov_wasserstein2',
5757
'entropic_gromov_barycenters', 'entropic_fused_gromov_wasserstein',
58-
'entropic_fused_gromov_wasserstein2', 'entropic_BAPG_fused_gromov_wasserstein',
59-
'entropic_BAPG_fused_gromov_wasserstein2', 'entropic_fused_gromov_barycenters',
58+
'entropic_fused_gromov_wasserstein2', 'BAPG_fused_gromov_wasserstein',
59+
'BAPG_fused_gromov_wasserstein2', 'entropic_fused_gromov_barycenters',
6060
'GW_distance_estimation', 'pointwise_gromov_wasserstein', 'sampled_gromov_wasserstein',
6161
'semirelaxed_gromov_wasserstein', 'semirelaxed_gromov_wasserstein2',
6262
'semirelaxed_fused_gromov_wasserstein', 'semirelaxed_fused_gromov_wasserstein2',

ot/gromov/_bregman.py

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,33 @@ def entropic_gromov_wasserstein2(
343343
return logv['gw_dist']
344344

345345

346-
def entropic_BAPG_gromov_wasserstein(
346+
def BAPG_gromov_wasserstein(
347347
C1, C2, p=None, q=None, loss_fun='square_loss', epsilon=0.1,
348348
symmetric=None, G0=None, max_iter=1000, tol=1e-9, marginal_loss=False,
349349
verbose=False, log=False):
350350
r"""
351351
Returns the Gromov-Wasserstein transport between :math:`(\mathbf{C_1}, \mathbf{p})` and :math:`(\mathbf{C_2}, \mathbf{q})`
352352
estimated using Bregman Alternated Projected Gradient method.
353353
354-
The function solves the following Gromov-Wasserstein
355-
optimization problem [63]:
354+
If `marginal_loss=True`, the function solves the following Gromov-Wasserstein
355+
optimization problem :
356356
357357
.. math::
358358
\mathbf{T}^* \in \mathop{\arg\min}_\mathbf{T} \quad \sum_{i,j,k,l} L(\mathbf{C_1}_{i,k}, \mathbf{C_2}_{j,l}) \mathbf{T}_{i,j} \mathbf{T}_{k,l}
359359
360+
s.t. \ \mathbf{T} \mathbf{1} &= \mathbf{p}
361+
362+
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
363+
364+
\mathbf{T} &\geq 0
365+
366+
Else, the function solves an equivalent problem [63], where constant terms only
367+
depending on the marginals :math:`\mathbf{p}`: and :math:`\mathbf{q}`: are
368+
discarded while assuming that L decomposes as in Proposition 1 in [12]:
369+
370+
.. math::
371+
\mathbf{T}^* \in\mathop{\arg\min}_\mathbf{T} \quad - \langle h_1(\mathbf{C}_1) \mathbf{T} h_2(\mathbf{C_2})^\top , \mathbf{T} \rangle_F
372+
360373
s.t. \ \mathbf{T} \mathbf{1} &= \mathbf{p}
361374
362375
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
@@ -369,6 +382,7 @@ def entropic_BAPG_gromov_wasserstein(
369382
- :math:`\mathbf{p}`: distribution in the source space
370383
- :math:`\mathbf{q}`: distribution in the target space
371384
- `L`: loss function to account for the misfit between the similarity matrices
385+
satisfying :math:`L(a, b) = f_1(a) + f_2(b) - h_1(a) h_2(b)`
372386
373387
.. note:: By algorithmic design the optimal coupling :math:`\mathbf{T}`
374388
returned by this function does not necessarily satisfy the marginal
@@ -407,7 +421,7 @@ def entropic_BAPG_gromov_wasserstein(
407421
tol : float, optional
408422
Stop threshold on error (>0)
409423
marginal_loss: bool, optional. Default is False.
410-
Include constant terms or not in the matching objective function.
424+
Include constant marginal terms or not in the objective function.
411425
verbose : bool, optional
412426
Print information along iterations
413427
log : bool, optional
@@ -524,19 +538,33 @@ def df(T):
524538
return T
525539

526540

527-
def entropic_BAPG_gromov_wasserstein2(
541+
def BAPG_gromov_wasserstein2(
528542
C1, C2, p=None, q=None, loss_fun='square_loss', epsilon=0.1, symmetric=None, G0=None, max_iter=1000,
529543
tol=1e-9, marginal_loss=False, verbose=False, log=False):
530544
r"""
531545
Returns the Gromov-Wasserstein loss :math:`\mathbf{GW}` between :math:`(\mathbf{C_1}, \mathbf{p})` and :math:`(\mathbf{C_2}, \mathbf{q})`
532546
estimated using Bregman Alternated Projected Gradient method.
533547
534-
The function solves the following Gromov-Wasserstein
535-
optimization problem [63]:
548+
If `marginal_loss=True`, the function solves the following Gromov-Wasserstein
549+
optimization problem :
550+
536551
537552
.. math::
538553
\mathbf{GW} = \mathop{\min}_\mathbf{T} \quad \sum_{i,j,k,l} L(\mathbf{C_1}_{i,k}, \mathbf{C_2}_{j,l}) \mathbf{T}_{i,j} \mathbf{T}_{k,l}
539554
555+
s.t. \ \mathbf{T} \mathbf{1} &= \mathbf{p}
556+
557+
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
558+
559+
\mathbf{T} &\geq 0
560+
561+
Else, the function solves an equivalent problem [63, 64], where constant terms only
562+
depending on the marginals :math:`\mathbf{p}`: and :math:`\mathbf{q}`: are
563+
discarded while assuming that L decomposes as in Proposition 1 in [12]:
564+
565+
.. math::
566+
\mathop{\min}_\mathbf{T} \quad - \langle h_1(\mathbf{C}_1) \mathbf{T} h_2(\mathbf{C_2})^\top , \mathbf{T} \rangle_F
567+
540568
s.t. \ \mathbf{T} \mathbf{1} &= \mathbf{p}
541569
542570
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
@@ -549,6 +577,7 @@ def entropic_BAPG_gromov_wasserstein2(
549577
- :math:`\mathbf{p}`: distribution in the source space
550578
- :math:`\mathbf{q}`: distribution in the target space
551579
- `L`: loss function to account for the misfit between the similarity matrices
580+
satisfying :math:`L(a, b) = f_1(a) + f_2(b) - h_1(a) h_2(b)`
552581
553582
.. note:: By algorithmic design the optimal coupling :math:`\mathbf{T}`
554583
returned by this function does not necessarily satisfy the marginal
@@ -588,7 +617,7 @@ def entropic_BAPG_gromov_wasserstein2(
588617
tol : float, optional
589618
Stop threshold on error (>0)
590619
marginal_loss: bool, optional. Default is False.
591-
Include constant terms or not in the matching objective function.
620+
Include constant marginal terms or not in the objective function.
592621
verbose : bool, optional
593622
Print information along iterations
594623
log : bool, optional
@@ -607,7 +636,7 @@ def entropic_BAPG_gromov_wasserstein2(
607636
608637
"""
609638

610-
T, logv = entropic_BAPG_gromov_wasserstein(
639+
T, logv = BAPG_gromov_wasserstein(
611640
C1, C2, p, q, loss_fun, epsilon, symmetric, G0, max_iter,
612641
tol, marginal_loss, verbose, log=True)
613642

@@ -1153,7 +1182,7 @@ def entropic_fused_gromov_wasserstein2(
11531182
return logv['fgw_dist']
11541183

11551184

1156-
def entropic_BAPG_fused_gromov_wasserstein(
1185+
def BAPG_fused_gromov_wasserstein(
11571186
M, C1, C2, p=None, q=None, loss_fun='square_loss', epsilon=0.1,
11581187
symmetric=None, alpha=0.5, G0=None, max_iter=1000, tol=1e-9,
11591188
marginal_loss=False, verbose=False, log=False):
@@ -1162,8 +1191,8 @@ def entropic_BAPG_fused_gromov_wasserstein(
11621191
with pairwise distance matrix :math:`\mathbf{M}` between node feature matrices :math:`\mathbf{Y_1}` and :math:`\mathbf{Y_2}`,
11631192
estimated using Bregman Alternated Projected Gradient method.
11641193
1165-
The function solves the following Fused Gromov-Wasserstein
1166-
optimization problem [63, 64]:
1194+
If `marginal_loss=True`, the function solves the following Fused Gromov-Wasserstein
1195+
optimization problem :
11671196
11681197
.. math::
11691198
\mathbf{T}^* \in\mathop{\arg\min}_\mathbf{T} \quad (1 - \alpha) \langle \mathbf{T}, \mathbf{M} \rangle_F +
@@ -1174,14 +1203,29 @@ def entropic_BAPG_fused_gromov_wasserstein(
11741203
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
11751204
11761205
\mathbf{T} &\geq 0
1206+
1207+
Else, the function solves an equivalent problem [63, 64], where constant terms only
1208+
depending on the marginals :math:`\mathbf{p}`: and :math:`\mathbf{q}`: are
1209+
discarded while assuming that L decomposes as in Proposition 1 in [12]:
1210+
1211+
.. math::
1212+
\mathbf{T}^* \in\mathop{\arg\min}_\mathbf{T} \quad (1 - \alpha) \langle \mathbf{T}, \mathbf{M} \rangle_F -
1213+
\alpha \langle h_1(\mathbf{C}_1) \mathbf{T} h_2(\mathbf{C_2})^\top , \mathbf{T} \rangle_F
1214+
s.t. \ \mathbf{T} \mathbf{1} &= \mathbf{p}
1215+
1216+
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
1217+
1218+
\mathbf{T} &\geq 0
1219+
11771220
Where :
11781221
1179-
- :math:`\mathbf{M}`: metric cost matrix between features across domains
1222+
- :math:`\mathbf{M}`: pairwise relation matrix between features across domains
11801223
- :math:`\mathbf{C_1}`: Metric cost matrix in the source space
11811224
- :math:`\mathbf{C_2}`: Metric cost matrix in the target space
11821225
- :math:`\mathbf{p}`: distribution in the source space
11831226
- :math:`\mathbf{q}`: distribution in the target space
11841227
- `L`: loss function to account for the misfit between the similarity and feature matrices
1228+
satisfying :math:`L(a, b) = f_1(a) + f_2(b) - h_1(a) h_2(b)`
11851229
- :math:`\alpha`: trade-off parameter
11861230
11871231
.. note:: By algorithmic design the optimal coupling :math:`\mathbf{T}`
@@ -1194,7 +1238,7 @@ def entropic_BAPG_fused_gromov_wasserstein(
11941238
Parameters
11951239
----------
11961240
M : array-like, shape (ns, nt)
1197-
Metric cost matrix between features across domains
1241+
Pairwise relation matrix between features across domains
11981242
C1 : array-like, shape (ns, ns)
11991243
Metric cost matrix in the source space
12001244
C2 : array-like, shape (nt, nt)
@@ -1225,7 +1269,7 @@ def entropic_BAPG_fused_gromov_wasserstein(
12251269
tol : float, optional
12261270
Stop threshold on error (>0)
12271271
marginal_loss: bool, optional. Default is False.
1228-
Include constant terms or not in the matching objective function.
1272+
Include constant marginal terms or not in the objective function.
12291273
verbose : bool, optional
12301274
Print information along iterations
12311275
log : bool, optional
@@ -1344,7 +1388,7 @@ def df(T):
13441388
return T
13451389

13461390

1347-
def entropic_BAPG_fused_gromov_wasserstein2(
1391+
def BAPG_fused_gromov_wasserstein2(
13481392
M, C1, C2, p=None, q=None, loss_fun='square_loss', epsilon=0.1,
13491393
symmetric=None, alpha=0.5, G0=None, max_iter=1000, tol=1e-9,
13501394
marginal_loss=False, verbose=False, log=False):
@@ -1353,8 +1397,8 @@ def entropic_BAPG_fused_gromov_wasserstein2(
13531397
with pairwise distance matrix :math:`\mathbf{M}` between node feature matrices :math:`\mathbf{Y_1}` and :math:`\mathbf{Y_2}`,
13541398
estimated using Bregman Alternated Projected Gradient method.
13551399
1356-
The function solves the following Fused Gromov-Wasserstein
1357-
optimization problem [63, 64]:
1400+
If `marginal_loss=True`, the function solves the following Fused Gromov-Wasserstein
1401+
optimization problem :
13581402
13591403
.. math::
13601404
\mathbf{FGW} = \mathop{\min}_\mathbf{T} \quad (1 - \alpha) \langle \mathbf{T}, \mathbf{M} \rangle_F +
@@ -1365,6 +1409,19 @@ def entropic_BAPG_fused_gromov_wasserstein2(
13651409
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
13661410
13671411
\mathbf{T} &\geq 0
1412+
1413+
Else, the function solves an equivalent problem [63, 64], where constant terms only
1414+
depending on the marginals :math:`\mathbf{p}`: and :math:`\mathbf{q}`: are
1415+
discarded while assuming that L decomposes as in Proposition 1 in [12]:
1416+
1417+
.. math::
1418+
\mathop{\min}_\mathbf{T} \quad (1 - \alpha) \langle \mathbf{T}, \mathbf{M} \rangle_F -
1419+
\alpha \langle h_1(\mathbf{C}_1) \mathbf{T} h_2(\mathbf{C_2})^\top , \mathbf{T} \rangle_F
1420+
s.t. \ \mathbf{T} \mathbf{1} &= \mathbf{p}
1421+
1422+
\mathbf{T}^T \mathbf{1} &= \mathbf{q}
1423+
1424+
\mathbf{T} &\geq 0
13681425
Where :
13691426
13701427
- :math:`\mathbf{M}`: metric cost matrix between features across domains
@@ -1373,6 +1430,7 @@ def entropic_BAPG_fused_gromov_wasserstein2(
13731430
- :math:`\mathbf{p}`: distribution in the source space
13741431
- :math:`\mathbf{q}`: distribution in the target space
13751432
- `L`: loss function to account for the misfit between the similarity and feature matrices
1433+
satisfying :math:`L(a, b) = f_1(a) + f_2(b) - h_1(a) h_2(b)`
13761434
- :math:`\alpha`: trade-off parameter
13771435
13781436
.. note:: By algorithmic design the optimal coupling :math:`\mathbf{T}`
@@ -1416,7 +1474,7 @@ def entropic_BAPG_fused_gromov_wasserstein2(
14161474
tol : float, optional
14171475
Stop threshold on error (>0)
14181476
marginal_loss: bool, optional. Default is False.
1419-
Include constant terms or not in the matching objective function.
1477+
Include constant marginal terms or not in the objective function.
14201478
verbose : bool, optional
14211479
Print information along iterations
14221480
log : bool, optional
@@ -1438,7 +1496,7 @@ def entropic_BAPG_fused_gromov_wasserstein2(
14381496
"""
14391497
nx = get_backend(M, C1, C2)
14401498

1441-
T, logv = entropic_BAPG_fused_gromov_wasserstein(
1499+
T, logv = BAPG_fused_gromov_wasserstein(
14421500
M, C1, C2, p, q, loss_fun, epsilon, symmetric, alpha, G0, max_iter,
14431501
tol, marginal_loss, verbose, log=True)
14441502

0 commit comments

Comments
 (0)