MCPcopy Create free account
hub / github.com/PythonOT/POT / test_entropic_coot

Function test_entropic_coot

test/test_coot.py:62–106  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

60
61
62def test_entropic_coot(nx):
63 n_samples = 60 # nb samples
64
65 mu_s = np.array([0, 0])
66 cov_s = np.array([[1, 0], [0, 1]])
67
68 xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s, random_state=4)
69 xt = xs[::-1].copy()
70 xs_nx = nx.from_numpy(xs)
71 xt_nx = nx.from_numpy(xt)
72
73 epsilon = (1, 1e-1)
74 nits_ot = 2000
75
76 # test couplings
77 pi_sample, pi_feature = coot(X=xs, Y=xt, epsilon=epsilon, nits_ot=nits_ot)
78 pi_sample_nx, pi_feature_nx = coot(
79 X=xs_nx, Y=xt_nx, epsilon=epsilon, nits_ot=nits_ot
80 )
81 pi_sample_nx = nx.to_numpy(pi_sample_nx)
82 pi_feature_nx = nx.to_numpy(pi_feature_nx)
83
84 np.testing.assert_allclose(pi_sample, pi_sample_nx, atol=1e-04)
85 np.testing.assert_allclose(pi_feature, pi_feature_nx, atol=1e-04)
86
87 # test marginal distributions
88 px_s, px_f = ot.unif(n_samples), ot.unif(2)
89 py_s, py_f = ot.unif(n_samples), ot.unif(2)
90
91 np.testing.assert_allclose(px_s, pi_sample_nx.sum(0), atol=1e-04)
92 np.testing.assert_allclose(py_s, pi_sample_nx.sum(1), atol=1e-04)
93 np.testing.assert_allclose(px_f, pi_feature_nx.sum(0), atol=1e-04)
94 np.testing.assert_allclose(py_f, pi_feature_nx.sum(1), atol=1e-04)
95
96 np.testing.assert_allclose(px_s, pi_sample.sum(0), atol=1e-04)
97 np.testing.assert_allclose(py_s, pi_sample.sum(1), atol=1e-04)
98 np.testing.assert_allclose(px_f, pi_feature.sum(0), atol=1e-04)
99 np.testing.assert_allclose(py_f, pi_feature.sum(1), atol=1e-04)
100
101 # test entropic COOT distance
102
103 coot_np = coot2(X=xs, Y=xt, epsilon=epsilon, nits_ot=nits_ot)
104 coot_nx = nx.to_numpy(coot2(X=xs_nx, Y=xt_nx, epsilon=epsilon, nits_ot=nits_ot))
105
106 np.testing.assert_allclose(coot_np, coot_nx, atol=1e-08)
107
108
109def test_coot_with_linear_terms(nx):

Callers

nothing calls this directly

Calls 4

from_numpyMethod · 0.80
to_numpyMethod · 0.80
copyMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected