|
4 | 4 | from fugw.solvers.utils import ( |
5 | 5 | solver_sinkhorn_stabilized_sparse, |
6 | 6 | solver_sinkhorn_eps_scaling_sparse, |
7 | | - solver_sinkhorn_stabilized, |
8 | | - solver_sinkhorn_eps_scaling, |
9 | 7 | ) |
10 | 8 |
|
11 | 9 |
|
12 | | -@pytest.mark.parametrize( |
13 | | - "pot_method, solver", |
14 | | - [ |
15 | | - ("sinkhorn_stabilized", solver_sinkhorn_stabilized), |
16 | | - ("sinkhorn_epsilon_scaling", solver_sinkhorn_eps_scaling), |
17 | | - ], |
18 | | -) |
19 | | -def test_solvers_sinkhorn(pot_method, solver): |
20 | | - """Test consistence of the dense sinkhorn solvers with POT.""" |
21 | | - ns = 151 |
22 | | - nt = 104 |
23 | | - nf = 10 |
24 | | - eps = 1.0 |
25 | | - |
26 | | - niters, tol, eval_freq = 100, 1e-7, 20 |
27 | | - |
28 | | - ws = torch.ones(ns) / ns |
29 | | - wt = torch.ones(nt) / nt |
30 | | - |
31 | | - source_features = torch.rand(ns, nf) |
32 | | - target_features = torch.rand(nt, nf) |
33 | | - |
34 | | - cost = torch.cdist(source_features, target_features) |
35 | | - |
36 | | - gamma, log = ot.sinkhorn( |
37 | | - ws, |
38 | | - wt, |
39 | | - cost, |
40 | | - eps, |
41 | | - numItermax=niters, |
42 | | - stopThr=tol, |
43 | | - method=pot_method, |
44 | | - print_period=eval_freq, |
45 | | - log=True, |
46 | | - ) |
47 | | - |
48 | | - # Check the potentials and the transport plan |
49 | | - (alpha, beta), pi = solver( |
50 | | - cost, |
51 | | - ws, |
52 | | - wt, |
53 | | - eps, |
54 | | - numItermax=niters, |
55 | | - tol=tol, |
56 | | - eval_freq=eval_freq, |
57 | | - ) |
58 | | - |
59 | | - assert torch.allclose( |
60 | | - log["alpha"], |
61 | | - alpha, |
62 | | - ) |
63 | | - assert torch.allclose(log["beta"], beta) |
64 | | - assert torch.allclose(gamma, pi) |
65 | | - |
66 | | - |
67 | 10 | @pytest.mark.parametrize( |
68 | 11 | "pot_method, solver", |
69 | 12 | [ |
|
0 commit comments