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

Function test_emd_laplace_class

test/test_da.py:841–908  ·  view source on GitHub ↗

test_emd_laplace_transport

(nx)

Source from the content-addressed store, hash-verified

839@pytest.skip_backend("jax")
840@pytest.skip_backend("tf")
841def test_emd_laplace_class(nx):
842 """test_emd_laplace_transport"""
843 ns = 50
844 nt = 50
845
846 Xs, ys = make_data_classif("3gauss", ns)
847 Xt, yt = make_data_classif("3gauss2", nt)
848
849 Xs, ys, Xt, yt = nx.from_numpy(Xs, ys, Xt, yt)
850
851 for log in [True, False]:
852 otda = ot.da.EMDLaplaceTransport(
853 reg_lap=0.01, max_iter=1000, tol=1e-9, verbose=False, log=log
854 )
855
856 # test its computed
857 otda.fit(Xs=Xs, ys=ys, Xt=Xt)
858
859 assert hasattr(otda, "coupling_")
860 assert hasattr(otda, "log_")
861
862 # test dimensions of coupling
863 assert_equal(otda.coupling_.shape, ((Xs.shape[0], Xt.shape[0])))
864
865 # test all margin constraints
866 mu_s = unif(ns)
867 mu_t = unif(nt)
868
869 assert_allclose(
870 nx.to_numpy(nx.sum(otda.coupling_, axis=0)), mu_t, rtol=1e-3, atol=1e-3
871 )
872 assert_allclose(
873 nx.to_numpy(nx.sum(otda.coupling_, axis=1)), mu_s, rtol=1e-3, atol=1e-3
874 )
875
876 # test transform
877 transp_Xs = otda.transform(Xs=Xs)
878 [assert_equal(x.shape, y.shape) for x, y in zip(transp_Xs, Xs)]
879
880 Xs_new = nx.from_numpy(make_data_classif("3gauss", ns + 1)[0])
881 transp_Xs_new = otda.transform(Xs_new)
882
883 # check that the oos method is working
884 assert_equal(transp_Xs_new.shape, Xs_new.shape)
885
886 # test inverse transform
887 transp_Xt = otda.inverse_transform(Xt=Xt)
888 assert_equal(transp_Xt.shape, Xt.shape)
889
890 Xt_new = nx.from_numpy(make_data_classif("3gauss2", nt + 1)[0])
891 transp_Xt_new = otda.inverse_transform(Xt=Xt_new)
892
893 # check that the oos method is working
894 assert_equal(transp_Xt_new.shape, Xt_new.shape)
895
896 # test fit_transform
897 transp_Xs = otda.fit_transform(Xs=Xs, Xt=Xt)
898 assert_equal(transp_Xs.shape, Xs.shape)

Callers

nothing calls this directly

Calls 12

fitMethod · 0.95
make_data_classifFunction · 0.90
unifFunction · 0.90
from_numpyMethod · 0.80
to_numpyMethod · 0.80
fit_transformMethod · 0.80
sumMethod · 0.45
transformMethod · 0.45
inverse_transformMethod · 0.45
transform_labelsMethod · 0.45
uniqueMethod · 0.45

Tested by

no test coverage detected