(nx, unbalanced_solver, divergence, eps)
| 443 | ), |
| 444 | ) |
| 445 | def test_linear_part(nx, unbalanced_solver, divergence, eps): |
| 446 | n_samples = 5 # nb samples |
| 447 | |
| 448 | mu_s = np.array([0, 0]) |
| 449 | cov_s = np.array([[1, 0], [0, 1]]) |
| 450 | |
| 451 | xs = ot.datasets.make_2D_samples_gauss(n_samples, mu_s, cov_s, random_state=4) |
| 452 | xt = xs[::-1].copy() |
| 453 | |
| 454 | px_s, px_f = ot.unif(n_samples), ot.unif(2) |
| 455 | py_s, py_f = ot.unif(n_samples), ot.unif(2) |
| 456 | |
| 457 | xs_nx, xt_nx = nx.from_numpy(xs, xt) |
| 458 | px_s_nx, px_f_nx, py_s_nx, py_f_nx = nx.from_numpy(px_s, px_f, py_s, py_f) |
| 459 | |
| 460 | # linear part |
| 461 | M_samp = np.ones((n_samples, n_samples)) |
| 462 | np.fill_diagonal(np.fliplr(M_samp), 0) |
| 463 | M_feat = np.ones((2, 2)) |
| 464 | np.fill_diagonal(M_feat, 0) |
| 465 | M_samp_nx, M_feat_nx = nx.from_numpy(M_samp, M_feat) |
| 466 | |
| 467 | reg_m = (10, 5) |
| 468 | alpha = (0.1, 0.2) |
| 469 | max_iter_ot = 5 |
| 470 | max_iter = 5 |
| 471 | tol = 1e-7 |
| 472 | tol_ot = 1e-7 |
| 473 | |
| 474 | # test couplings |
| 475 | pi_sample, pi_feature = unbalanced_co_optimal_transport( |
| 476 | X=xs, |
| 477 | Y=xt, |
| 478 | wx_samp=px_s, |
| 479 | wx_feat=px_f, |
| 480 | wy_samp=py_s, |
| 481 | wy_feat=py_f, |
| 482 | reg_marginals=reg_m, |
| 483 | epsilon=eps, |
| 484 | divergence=divergence, |
| 485 | unbalanced_solver=unbalanced_solver, |
| 486 | alpha=alpha, |
| 487 | M_samp=M_samp, |
| 488 | M_feat=M_feat, |
| 489 | init_pi=None, |
| 490 | init_duals=None, |
| 491 | max_iter=max_iter, |
| 492 | tol=tol, |
| 493 | max_iter_ot=max_iter_ot, |
| 494 | tol_ot=tol_ot, |
| 495 | log=False, |
| 496 | verbose=False, |
| 497 | ) |
| 498 | |
| 499 | pi_sample_nx, pi_feature_nx = unbalanced_co_optimal_transport( |
| 500 | X=xs_nx, |
| 501 | Y=xt_nx, |
| 502 | wx_samp=px_s_nx, |
nothing calls this directly
no test coverage detected