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

Function test_jcpot_transport_class

test/test_da.py:722–798  ·  view source on GitHub ↗

test_jcpot_transport

(nx)

Source from the content-addressed store, hash-verified

720@pytest.skip_backend("jax")
721@pytest.skip_backend("tf")
722def test_jcpot_transport_class(nx):
723 """test_jcpot_transport"""
724
725 ns1 = 50
726 ns2 = 50
727 nt = 50
728
729 Xs1, ys1 = make_data_classif("3gauss", ns1)
730 Xs2, ys2 = make_data_classif("3gauss", ns2)
731
732 Xt, yt = make_data_classif("3gauss2", nt)
733
734 Xs1, ys1, Xs2, ys2, Xt, yt = nx.from_numpy(Xs1, ys1, Xs2, ys2, Xt, yt)
735
736 Xs = [Xs1, Xs2]
737 ys = [ys1, ys2]
738
739 for log in [True, False]:
740 otda = ot.da.JCPOTTransport(
741 reg_e=1, max_iter=10000, tol=1e-9, verbose=True, log=log
742 )
743
744 # test its computed
745 otda.fit(Xs=Xs, ys=ys, Xt=Xt)
746
747 assert hasattr(otda, "coupling_")
748 assert hasattr(otda, "proportions_")
749 assert hasattr(otda, "log_")
750
751 # test dimensions of coupling
752 for i, xs in enumerate(Xs):
753 assert_equal(otda.coupling_[i].shape, ((xs.shape[0], Xt.shape[0])))
754
755 # test all margin constraints
756 mu_t = unif(nt)
757
758 for i in range(len(Xs)):
759 # test margin constraints w.r.t. uniform target weights for each coupling matrix
760 assert_allclose(
761 nx.to_numpy(nx.sum(otda.coupling_[i], axis=0)),
762 mu_t,
763 rtol=1e-3,
764 atol=1e-3,
765 )
766
767 if log:
768 # test margin constraints w.r.t. modified source weights for each source domain
769
770 assert_allclose(
771 nx.to_numpy(
772 nx.dot(otda.log_["D1"][i], nx.sum(otda.coupling_[i], axis=1))
773 ),
774 nx.to_numpy(otda.proportions_),
775 rtol=1e-3,
776 atol=1e-3,
777 )
778
779 # test transform

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected