summaryrefslogtreecommitdiff
path: root/test/test_optim.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_optim.py')
-rw-r--r--test/test_optim.py32
1 files changed, 15 insertions, 17 deletions
diff --git a/test/test_optim.py b/test/test_optim.py
index a77a37c..2840cad 100644
--- a/test/test_optim.py
+++ b/test/test_optim.py
@@ -1,24 +1,22 @@
-
-import ot
import numpy as np
+import ot
-# import pytest
def test_conditional_gradient():
- n = 100 # nb bins
+ n_bins = 100 # nb bins
np.random.seed(0)
# bin positions
- x = np.arange(n, dtype=np.float64)
+ x = np.arange(n_bins, dtype=np.float64)
# Gaussian distributions
- a = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
- b = ot.datasets.get_1D_gauss(n, m=60, s=10)
+ a = ot.datasets.get_1D_gauss(n_bins, m=20, s=5) # m= mean, s= std
+ b = ot.datasets.get_1D_gauss(n_bins, m=60, s=10)
# loss matrix
- M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
+ M = ot.dist(x.reshape((n_bins, 1)), x.reshape((n_bins, 1)))
M /= M.max()
def f(G):
@@ -31,23 +29,23 @@ def test_conditional_gradient():
G, log = ot.optim.cg(a, b, M, reg, f, df, verbose=True, log=True)
- assert np.allclose(a, G.sum(1))
- assert np.allclose(b, G.sum(0))
+ np.testing.assert_allclose(a, G.sum(1))
+ np.testing.assert_allclose(b, G.sum(0))
def test_generalized_conditional_gradient():
- n = 100 # nb bins
+ n_bins = 100 # nb bins
np.random.seed(0)
# bin positions
- x = np.arange(n, dtype=np.float64)
+ x = np.arange(n_bins, dtype=np.float64)
# Gaussian distributions
- a = ot.datasets.get_1D_gauss(n, m=20, s=5) # m= mean, s= std
- b = ot.datasets.get_1D_gauss(n, m=60, s=10)
+ a = ot.datasets.get_1D_gauss(n_bins, m=20, s=5) # m= mean, s= std
+ b = ot.datasets.get_1D_gauss(n_bins, m=60, s=10)
# loss matrix
- M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
+ M = ot.dist(x.reshape((n_bins, 1)), x.reshape((n_bins, 1)))
M /= M.max()
def f(G):
@@ -61,5 +59,5 @@ def test_generalized_conditional_gradient():
G, log = ot.optim.gcg(a, b, M, reg1, reg2, f, df, verbose=True, log=True)
- assert np.allclose(a, G.sum(1), atol=1e-05)
- assert np.allclose(b, G.sum(0), atol=1e-05)
+ np.testing.assert_allclose(a, G.sum(1), atol=1e-05)
+ np.testing.assert_allclose(b, G.sum(0), atol=1e-05)