| 13 | |
| 14 | |
| 15 | def test_raise_errors(): |
| 16 | n_samples = 20 # nb samples (gaussian) |
| 17 | n_noise = 20 # nb of samples (noise) |
| 18 | |
| 19 | mu = np.array([0, 0]) |
| 20 | cov = np.array([[1, 0], [0, 2]]) |
| 21 | |
| 22 | rng = np.random.RandomState(42) |
| 23 | xs = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov, random_state=rng) |
| 24 | xs = np.append(xs, (rng.rand(n_noise, 2) + 1) * 4).reshape((-1, 2)) |
| 25 | xt = ot.datasets.make_2D_samples_gauss(n_samples, mu, cov, random_state=rng) |
| 26 | xt = np.append(xt, (rng.rand(n_noise, 2) + 1) * -3).reshape((-1, 2)) |
| 27 | |
| 28 | M = ot.dist(xs, xt) |
| 29 | |
| 30 | p = ot.unif(n_samples + n_noise) |
| 31 | q = ot.unif(n_samples + n_noise) |
| 32 | |
| 33 | with pytest.raises(ValueError): |
| 34 | ot.partial.partial_wasserstein_lagrange(p + 1, q, M, 1, log=True) |
| 35 | |
| 36 | with pytest.raises(ValueError): |
| 37 | ot.partial.partial_wasserstein(p, q, M, m=2, log=True) |
| 38 | |
| 39 | with pytest.raises(ValueError): |
| 40 | ot.partial.partial_wasserstein(p, q, M, m=-1, log=True) |
| 41 | |
| 42 | with pytest.raises(ValueError): |
| 43 | ot.partial.entropic_partial_wasserstein(p, q, M, reg=1, m=2, log=True) |
| 44 | |
| 45 | with pytest.raises(ValueError): |
| 46 | ot.partial.entropic_partial_wasserstein(p, q, M, reg=1, m=-1, log=True) |
| 47 | |
| 48 | with pytest.raises(ValueError): |
| 49 | ot.partial.partial_gromov_wasserstein(M, M, p, q, m=2, log=True) |
| 50 | |
| 51 | with pytest.raises(ValueError): |
| 52 | ot.partial.partial_gromov_wasserstein(M, M, p, q, m=-1, log=True) |
| 53 | |
| 54 | with pytest.raises(ValueError): |
| 55 | ot.partial.entropic_partial_gromov_wasserstein(M, M, p, q, reg=1, m=2, log=True) |
| 56 | |
| 57 | with pytest.raises(ValueError): |
| 58 | ot.partial.entropic_partial_gromov_wasserstein( |
| 59 | M, M, p, q, reg=1, m=-1, log=True |
| 60 | ) |
| 61 | |
| 62 | with pytest.raises(AssertionError): |
| 63 | xs_2d = rng.randn(n_samples, 2) |
| 64 | xt_2d = rng.randn(n_samples, 2) |
| 65 | ot.partial.partial_wasserstein_1d(xs_2d, xt_2d) |
| 66 | |
| 67 | |
| 68 | def test_partial_wasserstein_lagrange(): |