summaryrefslogtreecommitdiff
path: root/test/test_da.py
diff options
context:
space:
mode:
authorSlasnista <stan.chambon@gmail.com>2017-09-05 09:42:32 +0200
committerSlasnista <stan.chambon@gmail.com>2017-09-05 09:42:32 +0200
commitb12edc59c0a94e1f426ae314baa006e06c062923 (patch)
tree3bbacbc5fe14d96c59060fa9ca1e2fb8c3b35062 /test/test_da.py
parent669a6bee4200f6a2f1f6bbf597712684ff7272a8 (diff)
integrated test for semi supervised case
Diffstat (limited to 'test/test_da.py')
-rw-r--r--test/test_da.py96
1 files changed, 60 insertions, 36 deletions
diff --git a/test/test_da.py b/test/test_da.py
index 104a798..a757d0a 100644
--- a/test/test_da.py
+++ b/test/test_da.py
@@ -63,19 +63,25 @@ def test_sinkhorn_lpl1_transport_class():
transp_Xs = clf.fit_transform(Xs=Xs, ys=ys, Xt=Xt)
assert_equal(transp_Xs.shape, Xs.shape)
- # test semi supervised mode
- clf = ot.da.SinkhornLpl1Transport()
- clf.fit(Xs=Xs, ys=ys, Xt=Xt)
- n_unsup = np.sum(clf.cost_)
+ # test unsupervised vs semi-supervised mode
+ clf_unsup = ot.da.SinkhornTransport()
+ clf_unsup.fit(Xs=Xs, Xt=Xt)
+ n_unsup = np.sum(clf_unsup.cost_)
- # test semi supervised mode
- clf = ot.da.SinkhornLpl1Transport()
- clf.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
- assert_equal(clf.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
- n_semisup = np.sum(clf.cost_)
+ clf_semi = ot.da.SinkhornTransport()
+ clf_semi.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
+ assert_equal(clf_semi.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
+ n_semisup = np.sum(clf_semi.cost_)
+ # check that the cost matrix norms are indeed different
assert n_unsup != n_semisup, "semisupervised mode not working"
+ # check that the coupling forbids mass transport between labeled source
+ # and labeled target samples
+ mass_semi = np.sum(
+ clf_semi.coupling_[clf_semi.cost_ == clf_semi.limit_max])
+ assert mass_semi == 0, "semisupervised mode not working"
+
def test_sinkhorn_l1l2_transport_class():
"""test_sinkhorn_transport
@@ -129,19 +135,25 @@ def test_sinkhorn_l1l2_transport_class():
transp_Xs = clf.fit_transform(Xs=Xs, ys=ys, Xt=Xt)
assert_equal(transp_Xs.shape, Xs.shape)
- # test semi supervised mode
- clf = ot.da.SinkhornL1l2Transport()
- clf.fit(Xs=Xs, ys=ys, Xt=Xt)
- n_unsup = np.sum(clf.cost_)
+ # test unsupervised vs semi-supervised mode
+ clf_unsup = ot.da.SinkhornTransport()
+ clf_unsup.fit(Xs=Xs, Xt=Xt)
+ n_unsup = np.sum(clf_unsup.cost_)
- # test semi supervised mode
- clf = ot.da.SinkhornL1l2Transport()
- clf.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
- assert_equal(clf.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
- n_semisup = np.sum(clf.cost_)
+ clf_semi = ot.da.SinkhornTransport()
+ clf_semi.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
+ assert_equal(clf_semi.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
+ n_semisup = np.sum(clf_semi.cost_)
+ # check that the cost matrix norms are indeed different
assert n_unsup != n_semisup, "semisupervised mode not working"
+ # check that the coupling forbids mass transport between labeled source
+ # and labeled target samples
+ mass_semi = np.sum(
+ clf_semi.coupling_[clf_semi.cost_ == clf_semi.limit_max])
+ assert mass_semi == 0, "semisupervised mode not working"
+
# check everything runs well with log=True
clf = ot.da.SinkhornL1l2Transport(log=True)
clf.fit(Xs=Xs, ys=ys, Xt=Xt)
@@ -200,19 +212,25 @@ def test_sinkhorn_transport_class():
transp_Xs = clf.fit_transform(Xs=Xs, Xt=Xt)
assert_equal(transp_Xs.shape, Xs.shape)
- # test semi supervised mode
- clf = ot.da.SinkhornTransport()
- clf.fit(Xs=Xs, Xt=Xt)
- n_unsup = np.sum(clf.cost_)
+ # test unsupervised vs semi-supervised mode
+ clf_unsup = ot.da.SinkhornTransport()
+ clf_unsup.fit(Xs=Xs, Xt=Xt)
+ n_unsup = np.sum(clf_unsup.cost_)
- # test semi supervised mode
- clf = ot.da.SinkhornTransport()
- clf.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
- assert_equal(clf.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
- n_semisup = np.sum(clf.cost_)
+ clf_semi = ot.da.SinkhornTransport()
+ clf_semi.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
+ assert_equal(clf_semi.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
+ n_semisup = np.sum(clf_semi.cost_)
+ # check that the cost matrix norms are indeed different
assert n_unsup != n_semisup, "semisupervised mode not working"
+ # check that the coupling forbids mass transport between labeled source
+ # and labeled target samples
+ mass_semi = np.sum(
+ clf_semi.coupling_[clf_semi.cost_ == clf_semi.limit_max])
+ assert mass_semi == 0, "semisupervised mode not working"
+
# check everything runs well with log=True
clf = ot.da.SinkhornTransport(log=True)
clf.fit(Xs=Xs, ys=ys, Xt=Xt)
@@ -270,19 +288,25 @@ def test_emd_transport_class():
transp_Xs = clf.fit_transform(Xs=Xs, Xt=Xt)
assert_equal(transp_Xs.shape, Xs.shape)
- # test semi supervised mode
- clf = ot.da.EMDTransport()
- clf.fit(Xs=Xs, Xt=Xt)
- n_unsup = np.sum(clf.cost_)
+ # test unsupervised vs semi-supervised mode
+ clf_unsup = ot.da.SinkhornTransport()
+ clf_unsup.fit(Xs=Xs, Xt=Xt)
+ n_unsup = np.sum(clf_unsup.cost_)
- # test semi supervised mode
- clf = ot.da.EMDTransport()
- clf.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
- assert_equal(clf.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
- n_semisup = np.sum(clf.cost_)
+ clf_semi = ot.da.SinkhornTransport()
+ clf_semi.fit(Xs=Xs, ys=ys, Xt=Xt, yt=yt)
+ assert_equal(clf_semi.cost_.shape, ((Xs.shape[0], Xt.shape[0])))
+ n_semisup = np.sum(clf_semi.cost_)
+ # check that the cost matrix norms are indeed different
assert n_unsup != n_semisup, "semisupervised mode not working"
+ # check that the coupling forbids mass transport between labeled source
+ # and labeled target samples
+ mass_semi = np.sum(
+ clf_semi.coupling_[clf_semi.cost_ == clf_semi.limit_max])
+ assert mass_semi == 0, "semisupervised mode not working"
+
def test_mapping_transport_class():
"""test_mapping_transport