(nx, verbose)
| 13 | |
| 14 | @pytest.mark.parametrize("verbose", [False, True, 1, 0]) |
| 15 | def test_coot(nx, verbose): |
| 16 | n_samples = 60 # nb samples |
| 17 | |
| 18 | mu_s = np.array([0, 0]) |
| 19 | cov_s = np.array([[1, 0], [0, 1]]) |
| 20 | |
| 21 | xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s, random_state=4) |
| 22 | xt = xs[::-1].copy() |
| 23 | xs_nx = nx.from_numpy(xs) |
| 24 | xt_nx = nx.from_numpy(xt) |
| 25 | |
| 26 | # test couplings |
| 27 | pi_sample, pi_feature = coot(X=xs, Y=xt, verbose=verbose) |
| 28 | pi_sample_nx, pi_feature_nx = coot(X=xs_nx, Y=xt_nx, verbose=verbose) |
| 29 | pi_sample_nx = nx.to_numpy(pi_sample_nx) |
| 30 | pi_feature_nx = nx.to_numpy(pi_feature_nx) |
| 31 | |
| 32 | anti_id_sample = np.flipud(np.eye(n_samples, n_samples)) / n_samples |
| 33 | id_feature = np.eye(2, 2) / 2 |
| 34 | |
| 35 | np.testing.assert_allclose(pi_sample, anti_id_sample, atol=1e-04) |
| 36 | np.testing.assert_allclose(pi_sample_nx, anti_id_sample, atol=1e-04) |
| 37 | np.testing.assert_allclose(pi_feature, id_feature, atol=1e-04) |
| 38 | np.testing.assert_allclose(pi_feature_nx, id_feature, atol=1e-04) |
| 39 | |
| 40 | # test marginal distributions |
| 41 | px_s, px_f = ot.unif(n_samples), ot.unif(2) |
| 42 | py_s, py_f = ot.unif(n_samples), ot.unif(2) |
| 43 | |
| 44 | np.testing.assert_allclose(px_s, pi_sample_nx.sum(0), atol=1e-04) |
| 45 | np.testing.assert_allclose(py_s, pi_sample_nx.sum(1), atol=1e-04) |
| 46 | np.testing.assert_allclose(px_f, pi_feature_nx.sum(0), atol=1e-04) |
| 47 | np.testing.assert_allclose(py_f, pi_feature_nx.sum(1), atol=1e-04) |
| 48 | |
| 49 | np.testing.assert_allclose(px_s, pi_sample.sum(0), atol=1e-04) |
| 50 | np.testing.assert_allclose(py_s, pi_sample.sum(1), atol=1e-04) |
| 51 | np.testing.assert_allclose(px_f, pi_feature.sum(0), atol=1e-04) |
| 52 | np.testing.assert_allclose(py_f, pi_feature.sum(1), atol=1e-04) |
| 53 | |
| 54 | # test COOT distance |
| 55 | |
| 56 | coot_np = coot2(X=xs, Y=xt, verbose=verbose) |
| 57 | coot_nx = nx.to_numpy(coot2(X=xs_nx, Y=xt_nx, verbose=verbose)) |
| 58 | np.testing.assert_allclose(coot_np, 0, atol=1e-08) |
| 59 | np.testing.assert_allclose(coot_nx, 0, atol=1e-08) |
| 60 | |
| 61 | |
| 62 | def test_entropic_coot(nx): |
nothing calls this directly
no test coverage detected