| 339 | |
| 340 | |
| 341 | def test_cost_normalization(nx): |
| 342 | rng = np.random.RandomState(0) |
| 343 | |
| 344 | C = rng.rand(10, 10) |
| 345 | C1 = nx.from_numpy(C) |
| 346 | |
| 347 | # does nothing |
| 348 | M0 = ot.utils.cost_normalization(C1) |
| 349 | M1 = nx.to_numpy(M0) |
| 350 | np.testing.assert_allclose(C, M1) |
| 351 | |
| 352 | M = ot.utils.cost_normalization(C1, "median") |
| 353 | M1 = nx.to_numpy(M) |
| 354 | np.testing.assert_allclose(np.median(M1), 1) |
| 355 | |
| 356 | M = ot.utils.cost_normalization(C1, "max") |
| 357 | M1 = nx.to_numpy(M) |
| 358 | np.testing.assert_allclose(M1.max(), 1) |
| 359 | |
| 360 | M = ot.utils.cost_normalization(C1, "log") |
| 361 | M1 = nx.to_numpy(M) |
| 362 | np.testing.assert_allclose(M1.max(), np.log(1 + C).max()) |
| 363 | |
| 364 | M = ot.utils.cost_normalization(C1, "loglog") |
| 365 | M1 = nx.to_numpy(M) |
| 366 | np.testing.assert_allclose(M1.max(), np.log(1 + np.log(1 + C)).max()) |
| 367 | |
| 368 | with pytest.raises(ValueError): |
| 369 | ot.utils.cost_normalization(C1, "error") |
| 370 | |
| 371 | |
| 372 | def test_list_to_array(nx): |