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

Function test_solve_gromov

test/test_solvers.py:374–408  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

372
373
374def test_solve_gromov(nx):
375 np.random.seed(0)
376
377 n_samples_s = 3
378 n_samples_t = 5
379
380 Ca = np.random.rand(n_samples_s, n_samples_s)
381 Ca = (Ca + Ca.T) / 2
382
383 Cb = np.random.rand(n_samples_t, n_samples_t)
384 Cb = (Cb + Cb.T) / 2
385
386 a = ot.utils.unif(n_samples_s)
387 b = ot.utils.unif(n_samples_t)
388
389 M = np.random.rand(n_samples_s, n_samples_t)
390
391 sol0 = ot.solve_gromov(Ca, Cb) # GW
392 sol = ot.solve_gromov(Ca, Cb, a=a, b=b) # GW
393 sol0_fgw = ot.solve_gromov(Ca, Cb, M) # FGW
394
395 # check some attributes
396 sol.potentials
397 sol.marginals
398
399 assert_allclose_sol(sol0, sol)
400
401 # solve in backend
402 ax, bx, Mx, Cax, Cbx = nx.from_numpy(a, b, M, Ca, Cb)
403
404 solx = ot.solve_gromov(Cax, Cbx, a=ax, b=bx) # GW
405 solx_fgw = ot.solve_gromov(Cax, Cbx, Mx) # FGW
406
407 assert_allclose_sol(sol, solx)
408 assert_allclose_sol(sol0_fgw, solx_fgw)
409
410
411@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

assert_allclose_solFunction · 0.85
from_numpyMethod · 0.80
seedMethod · 0.45
randMethod · 0.45

Tested by

no test coverage detected