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

Function test_solve_sample_geomloss

test/test_solvers.py:610–667  ·  view source on GitHub ↗
(nx, metric)

Source from the content-addressed store, hash-verified

608@pytest.skip_backend("jax")
609@pytest.mark.parametrize("metric", ["sqeuclidean", "euclidean"])
610def test_solve_sample_geomloss(nx, metric):
611 # test solve_sample when is_Lazy = False
612 n_samples_s = 13
613 n_samples_t = 7
614 n_features = 2
615 rng = np.random.RandomState(0)
616
617 x = rng.randn(n_samples_s, n_features)
618 y = rng.randn(n_samples_t, n_features)
619 a = ot.utils.unif(n_samples_s)
620 b = ot.utils.unif(n_samples_t)
621
622 xb, yb, ab, bb = nx.from_numpy(x, y, a, b)
623
624 sol0 = ot.solve_sample(xb, yb, ab, bb, reg=1)
625
626 # solve signe weights
627 sol = ot.solve_sample(xb, yb, ab, bb, reg=1, method="geomloss")
628 assert_allclose_sol(sol0, sol)
629
630 sol1 = ot.solve_sample(xb, yb, ab, bb, reg=1, lazy=False, method="geomloss")
631 assert_allclose_sol(sol0, sol)
632
633 sol1 = ot.solve_sample(
634 xb, yb, ab, bb, reg=1, lazy=True, method="geomloss_tensorized"
635 )
636 np.testing.assert_allclose(
637 nx.to_numpy(sol1.lazy_plan[:]),
638 nx.to_numpy(sol.lazy_plan[:]),
639 rtol=1e-5,
640 atol=1e-5,
641 )
642
643 sol1 = ot.solve_sample(xb, yb, ab, bb, reg=1, lazy=True, method="geomloss_online")
644 np.testing.assert_allclose(
645 nx.to_numpy(sol1.lazy_plan[:]),
646 nx.to_numpy(sol.lazy_plan[:]),
647 rtol=1e-5,
648 atol=1e-5,
649 )
650
651 sol1 = ot.solve_sample(
652 xb, yb, ab, bb, reg=1, lazy=True, method="geomloss_multiscale"
653 )
654 np.testing.assert_allclose(
655 nx.to_numpy(sol1.lazy_plan[:]),
656 nx.to_numpy(sol.lazy_plan[:]),
657 rtol=1e-5,
658 atol=1e-5,
659 )
660
661 sol1 = ot.solve_sample(xb, yb, ab, bb, reg=1, lazy=True, method="geomloss")
662 np.testing.assert_allclose(
663 nx.to_numpy(sol1.lazy_plan[:]),
664 nx.to_numpy(sol.lazy_plan[:]),
665 rtol=1e-5,
666 atol=1e-5,
667 )

Callers

nothing calls this directly

Calls 4

assert_allclose_solFunction · 0.85
from_numpyMethod · 0.80
to_numpyMethod · 0.80
randnMethod · 0.45

Tested by

no test coverage detected