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

Function test_cost_normalization

test/test_utils.py:341–369  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

339
340
341def 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
372def test_list_to_array(nx):

Callers

nothing calls this directly

Calls 6

from_numpyMethod · 0.80
to_numpyMethod · 0.80
randMethod · 0.45
medianMethod · 0.45
maxMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected