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

Function test_geomloss_solver

test/test_bregman.py:1166–1194  ·  view source on GitHub ↗
(nx, metric)

Source from the content-addressed store, hash-verified

1164@pytest.skip_backend("jax")
1165@pytest.mark.parametrize("metric", ["sqeuclidean", "euclidean"])
1166def test_geomloss_solver(nx, metric):
1167 # test sinkhorn
1168 n = 10
1169 a = ot.unif(n)
1170 b = ot.unif(n)
1171
1172 X_s = np.reshape(1.0 * np.arange(n), (n, 1))
1173 X_t = np.reshape(1.0 * np.arange(0, n), (n, 1))
1174
1175 ab, bb, X_sb, X_tb = nx.from_numpy(a, b, X_s, X_t)
1176
1177 G_sqe = nx.to_numpy(ot.bregman.empirical_sinkhorn(X_sb, X_tb, 1, metric=metric))
1178
1179 value, log = ot.bregman.empirical_sinkhorn2_geomloss(
1180 X_sb, X_tb, 1, metric=metric, log=True
1181 )
1182 G_geomloss = nx.to_numpy(log["lazy_plan"][:])
1183
1184 print(value)
1185
1186 # call with log = False
1187 ot.bregman.empirical_sinkhorn2_geomloss(X_sb, X_tb, 1, metric=metric)
1188
1189 # check equality of plans
1190 np.testing.assert_allclose(G_sqe, G_geomloss, atol=1e-03) # metric sqeuclidian
1191
1192 # check error on wrong metric
1193 with pytest.raises(ValueError):
1194 ot.bregman.empirical_sinkhorn2_geomloss(X_sb, X_tb, 1, metric="wrong_metric")
1195
1196
1197def test_lazy_empirical_sinkhorn(nx):

Callers

nothing calls this directly

Calls 4

from_numpyMethod · 0.80
to_numpyMethod · 0.80
reshapeMethod · 0.45
arangeMethod · 0.45

Tested by

no test coverage detected