diff options
author | RĂ©mi Flamary <remi.flamary@gmail.com> | 2022-04-07 14:18:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-07 14:18:54 +0200 |
commit | 0b223ff883fd73601984a92c31cb70d4aded16e8 (patch) | |
tree | bca74110049debfa35735f4618a9d1543690c2a4 /test | |
parent | ad02112d4288f3efdd5bc6fc6e45444313bba871 (diff) |
[MRG] Remove deprecated ot.gpu submodule (#361)
* remove all cpu submodule and tests
* speedup tests gromov
Diffstat (limited to 'test')
-rw-r--r-- | test/test_gpu.py | 106 | ||||
-rw-r--r-- | test/test_gromov.py | 129 |
2 files changed, 62 insertions, 173 deletions
diff --git a/test/test_gpu.py b/test/test_gpu.py deleted file mode 100644 index 8e62a74..0000000 --- a/test/test_gpu.py +++ /dev/null @@ -1,106 +0,0 @@ -"""Tests for module gpu for gpu acceleration """ - -# Author: Remi Flamary <remi.flamary@unice.fr> -# -# License: MIT License - -import numpy as np -import ot -import pytest - -try: # test if cudamat installed - import ot.gpu - nogpu = False -except ImportError: - nogpu = True - - -@pytest.mark.skipif(nogpu, reason="No GPU available") -def test_gpu_old_doctests(): - a = [.5, .5] - b = [.5, .5] - M = [[0., 1.], [1., 0.]] - G = ot.sinkhorn(a, b, M, 1) - np.testing.assert_allclose(G, np.array([[0.36552929, 0.13447071], - [0.13447071, 0.36552929]])) - - -@pytest.mark.skipif(nogpu, reason="No GPU available") -def test_gpu_dist(): - - rng = np.random.RandomState(0) - - for n_samples in [50, 100, 500, 1000]: - print(n_samples) - a = rng.rand(n_samples // 4, 100) - b = rng.rand(n_samples, 100) - - M = ot.dist(a.copy(), b.copy()) - M2 = ot.gpu.dist(a.copy(), b.copy()) - - np.testing.assert_allclose(M, M2, rtol=1e-10) - - M2 = ot.gpu.dist(a.copy(), b.copy(), metric='euclidean', to_numpy=False) - - # check raise not implemented wrong metric - with pytest.raises(NotImplementedError): - M2 = ot.gpu.dist(a.copy(), b.copy(), metric='cityblock', to_numpy=False) - - -@pytest.mark.skipif(nogpu, reason="No GPU available") -def test_gpu_sinkhorn(): - - rng = np.random.RandomState(0) - - for n_samples in [50, 100, 500, 1000]: - a = rng.rand(n_samples // 4, 100) - b = rng.rand(n_samples, 100) - - wa = ot.unif(n_samples // 4) - wb = ot.unif(n_samples) - - wb2 = np.random.rand(n_samples, 20) - wb2 /= wb2.sum(0, keepdims=True) - - M = ot.dist(a.copy(), b.copy()) - M2 = ot.gpu.dist(a.copy(), b.copy(), to_numpy=False) - - reg = 1 - - G = ot.sinkhorn(wa, wb, M, reg) - G1 = ot.gpu.sinkhorn(wa, wb, M, reg) - - np.testing.assert_allclose(G1, G, rtol=1e-10) - - # run all on gpu - ot.gpu.sinkhorn(wa, wb, M2, reg, to_numpy=False, log=True) - - # run sinkhorn for multiple targets - ot.gpu.sinkhorn(wa, wb2, M2, reg, to_numpy=False, log=True) - - -@pytest.mark.skipif(nogpu, reason="No GPU available") -def test_gpu_sinkhorn_lpl1(): - - rng = np.random.RandomState(0) - - for n_samples in [50, 100, 500]: - print(n_samples) - a = rng.rand(n_samples // 4, 100) - labels_a = np.random.randint(10, size=(n_samples // 4)) - b = rng.rand(n_samples, 100) - - wa = ot.unif(n_samples // 4) - wb = ot.unif(n_samples) - - M = ot.dist(a.copy(), b.copy()) - M2 = ot.gpu.dist(a.copy(), b.copy(), to_numpy=False) - - reg = 1 - - G = ot.da.sinkhorn_lpl1_mm(wa, labels_a, wb, M, reg) - G1 = ot.gpu.da.sinkhorn_lpl1_mm(wa, labels_a, wb, M, reg) - - np.testing.assert_allclose(G1, G, rtol=1e-10) - - ot.gpu.da.sinkhorn_lpl1_mm(wa, labels_a, wb, M2, reg, to_numpy=False, log=True) diff --git a/test/test_gromov.py b/test/test_gromov.py index 12fd2b9..9c85b92 100644 --- a/test/test_gromov.py +++ b/test/test_gromov.py @@ -188,7 +188,7 @@ def test_gromov2_gradients(): @pytest.skip_backend("jax", reason="test very slow with jax backend")
@pytest.skip_backend("tf", reason="test very slow with tf backend")
def test_entropic_gromov(nx):
- n_samples = 50 # nb samples
+ n_samples = 10 # nb samples
mu_s = np.array([0, 0])
cov_s = np.array([[1, 0], [0, 1]])
@@ -222,9 +222,9 @@ def test_entropic_gromov(nx): q, Gb.sum(0), atol=1e-04) # cf convergence gromov
gw, log = ot.gromov.entropic_gromov_wasserstein2(
- C1, C2, p, q, 'kl_loss', epsilon=1e-2, log=True)
+ C1, C2, p, q, 'kl_loss', max_iter=10, epsilon=1e-2, log=True)
gwb, logb = ot.gromov.entropic_gromov_wasserstein2(
- C1b, C2b, pb, qb, 'kl_loss', epsilon=1e-2, log=True)
+ C1b, C2b, pb, qb, 'kl_loss', max_iter=10, epsilon=1e-2, log=True)
gwb = nx.to_numpy(gwb)
G = log['T']
@@ -245,7 +245,7 @@ def test_entropic_gromov(nx): @pytest.skip_backend("tf", reason="test very slow with tf backend")
def test_entropic_gromov_dtype_device(nx):
# setup
- n_samples = 50 # nb samples
+ n_samples = 5 # nb samples
mu_s = np.array([0, 0])
cov_s = np.array([[1, 0], [0, 1]])
@@ -280,7 +280,7 @@ def test_entropic_gromov_dtype_device(nx): def test_pointwise_gromov(nx):
- n_samples = 50 # nb samples
+ n_samples = 5 # nb samples
mu_s = np.array([0, 0])
cov_s = np.array([[1, 0], [0, 1]])
@@ -331,14 +331,12 @@ def test_pointwise_gromov(nx): Gb = nx.to_numpy(nx.todense(Gb))
np.testing.assert_allclose(G, Gb, atol=1e-06)
- np.testing.assert_allclose(float(logb['gw_dist_estimated']), 0.10342276348494964, atol=1e-8)
- np.testing.assert_allclose(float(logb['gw_dist_std']), 0.0015952535464736394, atol=1e-8)
@pytest.skip_backend("tf", reason="test very slow with tf backend")
@pytest.skip_backend("jax", reason="test very slow with jax backend")
def test_sampled_gromov(nx):
- n_samples = 50 # nb samples
+ n_samples = 5 # nb samples
mu_s = np.array([0, 0], dtype=np.float64)
cov_s = np.array([[1, 0], [0, 1]], dtype=np.float64)
@@ -365,9 +363,9 @@ def test_sampled_gromov(nx): return nx.abs(x - y)
G, log = ot.gromov.sampled_gromov_wasserstein(
- C1, C2, p, q, loss, max_iter=100, epsilon=1, log=True, verbose=True, random_state=42)
+ C1, C2, p, q, loss, max_iter=20, nb_samples_grad=2, epsilon=1, log=True, verbose=True, random_state=42)
Gb, logb = ot.gromov.sampled_gromov_wasserstein(
- C1b, C2b, pb, qb, lossb, max_iter=100, epsilon=1, log=True, verbose=True, random_state=42)
+ C1b, C2b, pb, qb, lossb, max_iter=20, nb_samples_grad=2, epsilon=1, log=True, verbose=True, random_state=42)
Gb = nx.to_numpy(Gb)
# check constraints
@@ -377,13 +375,10 @@ def test_sampled_gromov(nx): np.testing.assert_allclose(
q, Gb.sum(0), atol=1e-04) # cf convergence gromov
- np.testing.assert_allclose(float(logb['gw_dist_estimated']), 0.05679474884977278, atol=1e-08)
- np.testing.assert_allclose(float(logb['gw_dist_std']), 0.0005986592106971995, atol=1e-08)
-
def test_gromov_barycenter(nx):
- ns = 10
- nt = 20
+ ns = 5
+ nt = 8
Xs, ys = ot.datasets.make_data_classif('3gauss', ns, random_state=42)
Xt, yt = ot.datasets.make_data_classif('3gauss2', nt, random_state=42)
@@ -450,8 +445,8 @@ def test_gromov_barycenter(nx): @pytest.mark.filterwarnings("ignore:divide")
def test_gromov_entropic_barycenter(nx):
- ns = 10
- nt = 20
+ ns = 5
+ nt = 10
Xs, ys = ot.datasets.make_data_classif('3gauss', ns, random_state=42)
Xt, yt = ot.datasets.make_data_classif('3gauss2', nt, random_state=42)
@@ -517,7 +512,7 @@ def test_gromov_entropic_barycenter(nx): def test_fgw(nx):
- n_samples = 50 # nb samples
+ n_samples = 20 # nb samples
mu_s = np.array([0, 0])
cov_s = np.array([[1, 0], [0, 1]])
@@ -579,7 +574,7 @@ def test_fgw(nx): def test_fgw2_gradients():
- n_samples = 50 # nb samples
+ n_samples = 20 # nb samples
mu_s = np.array([0, 0])
cov_s = np.array([[1, 0], [0, 1]])
@@ -625,8 +620,8 @@ def test_fgw2_gradients(): def test_fgw_barycenter(nx):
np.random.seed(42)
- ns = 50
- nt = 60
+ ns = 10
+ nt = 20
Xs, ys = ot.datasets.make_data_classif('3gauss', ns, random_state=42)
Xt, yt = ot.datasets.make_data_classif('3gauss2', nt, random_state=42)
@@ -674,7 +669,7 @@ def test_fgw_barycenter(nx): def test_gromov_wasserstein_linear_unmixing(nx):
- n = 10
+ n = 4
X1, y1 = ot.datasets.make_data_classif('3gauss', n, random_state=42)
X2, y2 = ot.datasets.make_data_classif('3gauss2', n, random_state=42)
@@ -709,10 +704,10 @@ def test_gromov_wasserstein_linear_unmixing(nx): tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
)
- np.testing.assert_allclose(unmixing1, nx.to_numpy(unmixing1b), atol=1e-06)
- np.testing.assert_allclose(unmixing1, [1., 0.], atol=1e-01)
- np.testing.assert_allclose(unmixing2, nx.to_numpy(unmixing2b), atol=1e-06)
- np.testing.assert_allclose(unmixing2, [0., 1.], atol=1e-01)
+ np.testing.assert_allclose(unmixing1, nx.to_numpy(unmixing1b), atol=5e-06)
+ np.testing.assert_allclose(unmixing1, [1., 0.], atol=5e-01)
+ np.testing.assert_allclose(unmixing2, nx.to_numpy(unmixing2b), atol=5e-06)
+ np.testing.assert_allclose(unmixing2, [0., 1.], atol=5e-01)
np.testing.assert_allclose(C1_emb, nx.to_numpy(C1b_emb), atol=1e-06)
np.testing.assert_allclose(C2_emb, nx.to_numpy(C2b_emb), atol=1e-06)
np.testing.assert_allclose(reconstruction1, nx.to_numpy(reconstruction1b), atol=1e-06)
@@ -758,7 +753,7 @@ def test_gromov_wasserstein_linear_unmixing(nx): def test_gromov_wasserstein_dictionary_learning(nx):
# create dataset composed from 2 structures which are repeated 5 times
- shape = 10
+ shape = 4
n_samples = 2
n_atoms = 2
projection = 'nonnegative_symmetric'
@@ -795,7 +790,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Cs[i], Cdict_init, p=ps[i], q=q, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
initial_total_reconstruction += reconstruction
@@ -803,7 +798,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): Cdict, log = ot.gromov.gromov_wasserstein_dictionary_learning(
Cs, D=n_atoms, nt=shape, ps=ps, q=q, Cdict_init=Cdict_init,
epochs=epochs, batch_size=2 * n_samples, learning_rate=1., reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary without backend
@@ -811,7 +806,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Cs[i], Cdict, p=None, q=None, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction += reconstruction
@@ -822,7 +817,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): Cdictb, log = ot.gromov.gromov_wasserstein_dictionary_learning(
Csb, D=n_atoms, nt=shape, ps=None, q=None, Cdict_init=Cdict_initb,
epochs=epochs, batch_size=n_samples, learning_rate=1., reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# Compute reconstruction of samples on learned dictionary
@@ -830,7 +825,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Csb[i], Cdictb, p=psb[i], q=qb, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_b += reconstruction
@@ -846,7 +841,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): Cdict_bis, log = ot.gromov.gromov_wasserstein_dictionary_learning(
Cs, D=n_atoms, nt=shape, ps=None, q=None, Cdict_init=None,
epochs=epochs, batch_size=n_samples, learning_rate=1., reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -854,7 +849,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Cs[i], Cdict_bis, p=ps[i], q=q, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_bis += reconstruction
@@ -865,7 +860,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): Cdictb_bis, log = ot.gromov.gromov_wasserstein_dictionary_learning(
Csb, D=n_atoms, nt=shape, ps=psb, q=qb, Cdict_init=None,
epochs=epochs, batch_size=n_samples, learning_rate=1., reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -873,7 +868,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Csb[i], Cdictb_bis, p=None, q=None, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_b_bis += reconstruction
@@ -892,7 +887,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): Cdict_bis2, log = ot.gromov.gromov_wasserstein_dictionary_learning(
Cs, D=n_atoms, nt=shape, ps=ps, q=q, Cdict_init=Cdict,
epochs=epochs, batch_size=n_samples, learning_rate=10., reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=use_log, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -900,7 +895,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Cs[i], Cdict_bis2, p=ps[i], q=q, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_bis2 += reconstruction
@@ -911,7 +906,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): Cdictb_bis2, log = ot.gromov.gromov_wasserstein_dictionary_learning(
Csb, D=n_atoms, nt=shape, ps=psb, q=qb, Cdict_init=Cdictb,
epochs=epochs, batch_size=n_samples, learning_rate=10., reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=use_log, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -919,7 +914,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, reconstruction = ot.gromov.gromov_wasserstein_linear_unmixing(
Csb[i], Cdictb_bis2, p=psb[i], q=qb, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_b_bis2 += reconstruction
@@ -929,7 +924,7 @@ def test_gromov_wasserstein_dictionary_learning(nx): def test_fused_gromov_wasserstein_linear_unmixing(nx):
- n = 10
+ n = 4
X1, y1 = ot.datasets.make_data_classif('3gauss', n, random_state=42)
X2, y2 = ot.datasets.make_data_classif('3gauss2', n, random_state=42)
F, y = ot.datasets.make_data_classif('3gauss', n, random_state=42)
@@ -947,28 +942,28 @@ def test_fused_gromov_wasserstein_linear_unmixing(nx): unmixing1, C1_emb, Y1_emb, OT, reconstruction1 = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C1, F, Cdict, Ydict, p=p, q=p, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
unmixing1b, C1b_emb, Y1b_emb, OTb, reconstruction1b = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C1b, Fb, Cdictb, Ydictb, p=None, q=None, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
unmixing2, C2_emb, Y2_emb, OT, reconstruction2 = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C2, F, Cdict, Ydict, p=None, q=None, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
unmixing2b, C2b_emb, Y2b_emb, OTb, reconstruction2b = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C2b, Fb, Cdictb, Ydictb, p=pb, q=pb, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
- np.testing.assert_allclose(unmixing1, nx.to_numpy(unmixing1b), atol=1e-06)
- np.testing.assert_allclose(unmixing1, [1., 0.], atol=1e-01)
- np.testing.assert_allclose(unmixing2, nx.to_numpy(unmixing2b), atol=1e-06)
- np.testing.assert_allclose(unmixing2, [0., 1.], atol=1e-01)
+ np.testing.assert_allclose(unmixing1, nx.to_numpy(unmixing1b), atol=4e-06)
+ np.testing.assert_allclose(unmixing1, [1., 0.], atol=4e-01)
+ np.testing.assert_allclose(unmixing2, nx.to_numpy(unmixing2b), atol=4e-06)
+ np.testing.assert_allclose(unmixing2, [0., 1.], atol=4e-01)
np.testing.assert_allclose(C1_emb, nx.to_numpy(C1b_emb), atol=1e-03)
np.testing.assert_allclose(C2_emb, nx.to_numpy(C2b_emb), atol=1e-03)
np.testing.assert_allclose(Y1_emb, nx.to_numpy(Y1b_emb), atol=1e-03)
@@ -983,22 +978,22 @@ def test_fused_gromov_wasserstein_linear_unmixing(nx): unmixing1, C1_emb, Y1_emb, OT, reconstruction1 = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C1, F, Cdict, Ydict, p=p, q=p, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
unmixing1b, C1b_emb, Y1b_emb, OTb, reconstruction1b = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C1b, Fb, Cdictb, Ydictb, p=None, q=None, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
unmixing2, C2_emb, Y2_emb, OT, reconstruction2 = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C2, F, Cdict, Ydict, p=None, q=None, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
unmixing2b, C2b_emb, Y2b_emb, OTb, reconstruction2b = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
C2b, Fb, Cdictb, Ydictb, p=pb, q=pb, alpha=0.5, reg=reg,
- tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=20, max_iter_inner=200
+ tol_outer=10**(-6), tol_inner=10**(-6), max_iter_outer=10, max_iter_inner=50
)
np.testing.assert_allclose(unmixing1, nx.to_numpy(unmixing1b), atol=1e-06)
@@ -1018,7 +1013,7 @@ def test_fused_gromov_wasserstein_linear_unmixing(nx): def test_fused_gromov_wasserstein_dictionary_learning(nx):
# create dataset composed from 2 structures which are repeated 5 times
- shape = 10
+ shape = 4
n_samples = 2
n_atoms = 2
projection = 'nonnegative_symmetric'
@@ -1060,7 +1055,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Cs[i], Ys[i], Cdict_init, Ydict_init, p=ps[i], q=q,
- alpha=alpha, reg=0., tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ alpha=alpha, reg=0., tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
initial_total_reconstruction += reconstruction
@@ -1069,7 +1064,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): Cdict, Ydict, log = ot.gromov.fused_gromov_wasserstein_dictionary_learning(
Cs, Ys, D=n_atoms, nt=shape, ps=ps, q=q, Cdict_init=Cdict_init, Ydict_init=Ydict_init,
epochs=epochs, batch_size=n_samples, learning_rate_C=1., learning_rate_Y=1., alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -1077,7 +1072,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Cs[i], Ys[i], Cdict, Ydict, p=None, q=None, alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction += reconstruction
# Compare both
@@ -1088,7 +1083,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): Cdictb, Ydictb, log = ot.gromov.fused_gromov_wasserstein_dictionary_learning(
Csb, Ysb, D=n_atoms, nt=shape, ps=None, q=None, Cdict_init=Cdict_initb, Ydict_init=Ydict_initb,
epochs=epochs, batch_size=2 * n_samples, learning_rate_C=1., learning_rate_Y=1., alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -1096,7 +1091,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Csb[i], Ysb[i], Cdictb, Ydictb, p=psb[i], q=qb, alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_b += reconstruction
@@ -1111,7 +1106,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): Cdict_bis, Ydict_bis, log = ot.gromov.fused_gromov_wasserstein_dictionary_learning(
Cs, Ys, D=n_atoms, nt=shape, ps=None, q=None, Cdict_init=None, Ydict_init=None,
epochs=epochs, batch_size=n_samples, learning_rate_C=1., learning_rate_Y=1., alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -1119,7 +1114,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Cs[i], Ys[i], Cdict_bis, Ydict_bis, p=ps[i], q=q, alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_bis += reconstruction
@@ -1130,7 +1125,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): Cdictb_bis, Ydictb_bis, log = ot.gromov.fused_gromov_wasserstein_dictionary_learning(
Csb, Ysb, D=n_atoms, nt=shape, ps=None, q=None, Cdict_init=None, Ydict_init=None,
epochs=epochs, batch_size=n_samples, learning_rate_C=1., learning_rate_Y=1., alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=False, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
@@ -1139,7 +1134,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Csb[i], Ysb[i], Cdictb_bis, Ydictb_bis, p=psb[i], q=qb, alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_b_bis += reconstruction
@@ -1156,7 +1151,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): Cdict_bis2, Ydict_bis2, log = ot.gromov.fused_gromov_wasserstein_dictionary_learning(
Cs, Ys, D=n_atoms, nt=shape, ps=ps, q=q, Cdict_init=Cdict, Ydict_init=Ydict,
epochs=epochs, batch_size=n_samples, learning_rate_C=10., learning_rate_Y=10., alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=use_log, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
# > Compute reconstruction of samples on learned dictionary
@@ -1164,7 +1159,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Cs[i], Ys[i], Cdict_bis2, Ydict_bis2, p=ps[i], q=q, alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_bis2 += reconstruction
@@ -1175,7 +1170,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): Cdictb_bis2, Ydictb_bis2, log = ot.gromov.fused_gromov_wasserstein_dictionary_learning(
Csb, Ysb, D=n_atoms, nt=shape, ps=None, q=None, Cdict_init=Cdictb, Ydict_init=Ydictb,
epochs=epochs, batch_size=n_samples, learning_rate_C=10., learning_rate_Y=10., alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200,
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50,
projection=projection, use_log=use_log, use_adam_optimizer=use_adam_optimizer, verbose=verbose
)
@@ -1184,7 +1179,7 @@ def test_fused_gromov_wasserstein_dictionary_learning(nx): for i in range(n_samples):
_, _, _, _, reconstruction = ot.gromov.fused_gromov_wasserstein_linear_unmixing(
Csb[i], Ysb[i], Cdictb_bis2, Ydictb_bis2, p=None, q=None, alpha=alpha, reg=0.,
- tol_outer=tol, tol_inner=tol, max_iter_outer=20, max_iter_inner=200
+ tol_outer=tol, tol_inner=tol, max_iter_outer=10, max_iter_inner=50
)
total_reconstruction_b_bis2 += reconstruction
|