From 74d9322bd528e59dd457377d902fa30172d1c5a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Flamary?= Date: Mon, 19 Apr 2021 13:16:59 +0200 Subject: [PATCH 1/3] remove warnings in tests from docstrings --- ot/da.py | 12 ++++++------ ot/dr.py | 2 +- ot/gromov.py | 20 ++++++++++---------- ot/lp/cvx.py | 3 +-- ot/optim.py | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ot/da.py b/ot/da.py index f1e4769c9..cdc747c67 100644 --- a/ot/da.py +++ b/ot/da.py @@ -26,7 +26,7 @@ def sinkhorn_lpl1_mm(a, labels_a, b, M, reg, eta=0.1, numItermax=10, numInnerItermax=200, stopInnerThr=1e-9, verbose=False, log=False): - """ + r""" Solve the entropic regularization optimal transport problem with nonconvex group lasso regularization @@ -137,7 +137,7 @@ def sinkhorn_lpl1_mm(a, labels_a, b, M, reg, eta=0.1, numItermax=10, def sinkhorn_l1l2_gl(a, labels_a, b, M, reg, eta=0.1, numItermax=10, numInnerItermax=200, stopInnerThr=1e-9, verbose=False, log=False): - """ + r""" Solve the entropic regularization optimal transport problem with group lasso regularization @@ -245,7 +245,7 @@ def joint_OT_mapping_linear(xs, xt, mu=1, eta=0.001, bias=False, verbose=False, verbose2=False, numItermax=100, numInnerItermax=10, stopInnerThr=1e-6, stopThr=1e-5, log=False, **kwargs): - """Joint OT and linear mapping estimation as proposed in [8] + r"""Joint OT and linear mapping estimation as proposed in [8] The function solves the following optimization problem: @@ -434,7 +434,7 @@ def joint_OT_mapping_kernel(xs, xt, mu=1, eta=0.001, kerneltype='gaussian', numItermax=100, numInnerItermax=10, stopInnerThr=1e-6, stopThr=1e-5, log=False, **kwargs): - """Joint OT and nonlinear mapping estimation with kernels as proposed in [8] + r"""Joint OT and nonlinear mapping estimation with kernels as proposed in [8] The function solves the following optimization problem: @@ -645,7 +645,7 @@ def df(G): def OT_mapping_linear(xs, xt, reg=1e-6, ws=None, wt=None, bias=True, log=False): - """ return OT linear operator between samples + r""" return OT linear operator between samples The function estimates the optimal linear operator that aligns the two empirical distributions. This is equivalent to estimating the closed @@ -1228,7 +1228,7 @@ def inverse_transform_labels(self, yt=None): class LinearTransport(BaseTransport): - """ OT linear operator between empirical distributions + r""" OT linear operator between empirical distributions The function estimates the optimal linear operator that aligns the two empirical distributions. This is equivalent to estimating the closed diff --git a/ot/dr.py b/ot/dr.py index 11d2e101f..b7a1af067 100644 --- a/ot/dr.py +++ b/ot/dr.py @@ -109,7 +109,7 @@ def proj(X): def wda(X, y, p=2, reg=1, k=10, solver=None, maxiter=100, verbose=0, P0=None): - """ + r""" Wasserstein Discriminant Analysis [11]_ The function solves the following optimization problem: diff --git a/ot/gromov.py b/ot/gromov.py index 4427a9631..8f457e9ec 100644 --- a/ot/gromov.py +++ b/ot/gromov.py @@ -19,7 +19,7 @@ def init_matrix(C1, C2, p, q, loss_fun='square_loss'): - """Return loss matrices and tensors for Gromov-Wasserstein fast computation + r"""Return loss matrices and tensors for Gromov-Wasserstein fast computation Returns the value of \mathcal{L}(C1,C2) \otimes T with the selected loss function as the loss function of Gromow-Wasserstein discrepancy. @@ -109,7 +109,7 @@ def h2(b): def tensor_product(constC, hC1, hC2, T): - """Return the tensor for Gromov-Wasserstein fast computation + r"""Return the tensor for Gromov-Wasserstein fast computation The tensor is computed as described in Proposition 1 Eq. (6) in [12]. @@ -262,7 +262,7 @@ def update_kl_loss(p, lambdas, T, Cs): def gromov_wasserstein(C1, C2, p, q, loss_fun, log=False, armijo=False, **kwargs): - """ + r""" Returns the gromov-wasserstein transport between (C1,p) and (C2,q) The function solves the following optimization problem: @@ -343,7 +343,7 @@ def df(G): def gromov_wasserstein2(C1, C2, p, q, loss_fun, log=False, armijo=False, **kwargs): - """ + r""" Returns the gromov-wasserstein discrepancy between (C1,p) and (C2,q) The function solves the following optimization problem: @@ -420,7 +420,7 @@ def df(G): def fused_gromov_wasserstein(M, C1, C2, p, q, loss_fun='square_loss', alpha=0.5, armijo=False, log=False, **kwargs): - """ + r""" Computes the FGW transport between two graphs see [24] .. math:: @@ -496,7 +496,7 @@ def df(G): def fused_gromov_wasserstein2(M, C1, C2, p, q, loss_fun='square_loss', alpha=0.5, armijo=False, log=False, **kwargs): - """ + r""" Computes the FGW distance between two graphs see [24] .. math:: @@ -574,7 +574,7 @@ def df(G): def entropic_gromov_wasserstein(C1, C2, p, q, loss_fun, epsilon, max_iter=1000, tol=1e-9, verbose=False, log=False): - """ + r""" Returns the gromov-wasserstein transport between (C1,p) and (C2,q) (C1,p) and (C2,q) @@ -681,7 +681,7 @@ def entropic_gromov_wasserstein(C1, C2, p, q, loss_fun, epsilon, def entropic_gromov_wasserstein2(C1, C2, p, q, loss_fun, epsilon, max_iter=1000, tol=1e-9, verbose=False, log=False): - """ + r""" Returns the entropic gromov-wasserstein discrepancy between the two measured similarity matrices (C1,p) and (C2,q) @@ -747,7 +747,7 @@ def entropic_gromov_wasserstein2(C1, C2, p, q, loss_fun, epsilon, def entropic_gromov_barycenters(N, Cs, ps, p, lambdas, loss_fun, epsilon, max_iter=1000, tol=1e-9, verbose=False, log=False, init_C=None): - """ + r""" Returns the gromov-wasserstein barycenters of S measured similarity matrices (Cs)_{s=1}^{s=S} @@ -857,7 +857,7 @@ def entropic_gromov_barycenters(N, Cs, ps, p, lambdas, loss_fun, epsilon, def gromov_barycenters(N, Cs, ps, p, lambdas, loss_fun, max_iter=1000, tol=1e-9, verbose=False, log=False, init_C=None): - """ + r""" Returns the gromov-wasserstein barycenters of S measured similarity matrices (Cs)_{s=1}^{s=S} diff --git a/ot/lp/cvx.py b/ot/lp/cvx.py index 8e763bef4..869d450bb 100644 --- a/ot/lp/cvx.py +++ b/ot/lp/cvx.py @@ -27,7 +27,7 @@ def scipy_sparse_to_spmatrix(A): def barycenter(A, M, weights=None, verbose=False, log=False, solver='interior-point'): - """Compute the Wasserstein barycenter of distributions A + r"""Compute the Wasserstein barycenter of distributions A The function solves the following optimization problem [16]: @@ -76,7 +76,6 @@ def barycenter(A, M, weights=None, verbose=False, log=False, solver='interior-po .. [16] Agueh, M., & Carlier, G. (2011). Barycenters in the Wasserstein space. SIAM Journal on Mathematical Analysis, 43(2), 904-924. - """ if weights is None: diff --git a/ot/optim.py b/ot/optim.py index 190290745..abe9e6aaf 100644 --- a/ot/optim.py +++ b/ot/optim.py @@ -139,7 +139,7 @@ def solve_linesearch(cost, G, deltaG, Mi, f_val, def cg(a, b, M, reg, f, df, G0=None, numItermax=200, numItermaxEmd=100000, stopThr=1e-9, stopThr2=1e-9, verbose=False, log=False, **kwargs): - """ + r""" Solve the general regularized OT problem with conditional gradient The function solves the following optimization problem: @@ -278,7 +278,7 @@ def cost(G): def gcg(a, b, M, reg1, reg2, f, df, G0=None, numItermax=10, numInnerItermax=200, stopThr=1e-9, stopThr2=1e-9, verbose=False, log=False): - """ + r""" Solve the general regularized OT problem with the generalized conditional gradient The function solves the following optimization problem: From 0043ede8df772b2f1803e17f7525957322e3aa43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Flamary?= Date: Mon, 19 Apr 2021 13:43:06 +0200 Subject: [PATCH 2/3] working tets for bregman implemneted methods --- ot/gpu/bregman.py | 2 +- test/test_bregman.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ot/gpu/bregman.py b/ot/gpu/bregman.py index 2e2df8334..82f34f384 100644 --- a/ot/gpu/bregman.py +++ b/ot/gpu/bregman.py @@ -15,7 +15,7 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000, stopThr=1e-9, verbose=False, log=False, to_numpy=True, **kwargs): - """ + r""" Solve the entropic regularization optimal transport on GPU If the input matrix are in numpy format, they will be uploaded to the diff --git a/test/test_bregman.py b/test/test_bregman.py index 6aa4e08ed..c70cbb5b8 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -320,8 +320,9 @@ def test_implemented_methods(): # make dists unbalanced b = ot.utils.unif(n) A = rng.rand(n, 2) + A /= A.sum(0,keepdims=True) M = ot.dist(x, x) - epsilon = 1. + epsilon = 1.0 for method in IMPLEMENTED_METHODS: ot.bregman.sinkhorn(a, b, M, epsilon, method=method) From 0d1ba4b7769484761ac818b6bdb4d2c05072294a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Flamary?= Date: Mon, 19 Apr 2021 13:45:17 +0200 Subject: [PATCH 3/3] pep8 --- test/test_bregman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_bregman.py b/test/test_bregman.py index c70cbb5b8..0ebf1f930 100644 --- a/test/test_bregman.py +++ b/test/test_bregman.py @@ -320,7 +320,7 @@ def test_implemented_methods(): # make dists unbalanced b = ot.utils.unif(n) A = rng.rand(n, 2) - A /= A.sum(0,keepdims=True) + A /= A.sum(0, keepdims=True) M = ot.dist(x, x) epsilon = 1.0