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

Function test_sanity

test/test_ucoot.py:22–154  ·  view source on GitHub ↗
(nx, unbalanced_solver, divergence)

Source from the content-addressed store, hash-verified

20 "unbalanced_solver, divergence", itertools.product(["mm", "lbfgsb"], ["kl", "l2"])
21)
22def test_sanity(nx, unbalanced_solver, divergence):
23 n_samples = 5 # nb samples
24
25 mu_s = np.array([0, 0])
26 cov_s = np.array([[1, 0], [0, 1]])
27
28 xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s, random_state=4)
29 xt = xs[::-1].copy()
30
31 px_s, px_f = ot.unif(n_samples), ot.unif(2)
32 py_s, py_f = ot.unif(n_samples), ot.unif(2)
33
34 xs_nx, xt_nx = nx.from_numpy(xs, xt)
35 px_s_nx, px_f_nx, py_s_nx, py_f_nx = nx.from_numpy(px_s, px_f, py_s, py_f)
36
37 reg_m = (10, 5)
38 eps = 0
39 max_iter_ot = 200
40 max_iter = 200
41 tol = 1e-7
42 tol_ot = 1e-7
43
44 # test couplings
45 anti_id_sample = np.flipud(np.eye(n_samples, n_samples)) / n_samples
46 id_feature = np.eye(2, 2) / 2
47
48 pi_sample, pi_feature = unbalanced_co_optimal_transport(
49 X=xs,
50 Y=xt,
51 wx_samp=px_s,
52 wx_feat=px_f,
53 wy_samp=py_s,
54 wy_feat=py_f,
55 reg_marginals=reg_m,
56 epsilon=eps,
57 divergence=divergence,
58 unbalanced_solver=unbalanced_solver,
59 alpha=0,
60 M_samp=None,
61 M_feat=None,
62 init_pi=None,
63 init_duals=None,
64 max_iter=max_iter,
65 tol=tol,
66 max_iter_ot=max_iter_ot,
67 tol_ot=tol_ot,
68 log=False,
69 verbose=False,
70 )
71
72 pi_sample_nx, pi_feature_nx = unbalanced_co_optimal_transport(
73 X=xs_nx,
74 Y=xt_nx,
75 wx_samp=px_s_nx,
76 wx_feat=px_f_nx,
77 wy_samp=py_s_nx,
78 wy_feat=py_f_nx,
79 reg_marginals=reg_m,

Callers

nothing calls this directly

Calls 6

from_numpyMethod · 0.80
to_numpyMethod · 0.80
copyMethod · 0.45
eyeMethod · 0.45

Tested by

no test coverage detected