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

Function test_prw

test/test_dr.py:111–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

109
110@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)")
111def test_prw():
112 d = 100 # Dimension
113 n = 100 # Number samples
114 k = 3 # Subspace dimension
115 dim = 3
116
117 def fragmented_hypercube(n, d, dim, rng):
118 assert dim <= d
119 assert dim >= 1
120 assert dim == int(dim)
121
122 a = (1.0 / n) * np.ones(n)
123 b = (1.0 / n) * np.ones(n)
124
125 # First measure : uniform on the hypercube
126 X = rng.uniform(-1, 1, size=(n, d))
127
128 # Second measure : fragmentation
129 tmp_y = rng.uniform(-1, 1, size=(n, d))
130 Y = tmp_y + 2 * np.sign(tmp_y) * np.array(dim * [1] + (d - dim) * [0])
131 return a, b, X, Y
132
133 rng = np.random.RandomState(42)
134 a, b, X, Y = fragmented_hypercube(n, d, dim, rng)
135
136 tau = 0.002
137 reg = 0.2
138
139 pi, U = ot.dr.projection_robust_wasserstein(
140 X, Y, a, b, tau, reg=reg, k=k, maxiter=1000, verbose=1
141 )
142
143 U0 = rng.randn(d, k)
144 U0, _ = np.linalg.qr(U0)
145
146 pi, U = ot.dr.projection_robust_wasserstein(
147 X, Y, a, b, tau, U0=U0, reg=reg, k=k, maxiter=1000, verbose=1
148 )
149
150
151@pytest.mark.skipif(nogo, reason="Missing modules (autograd or pymanopt)")

Callers

nothing calls this directly

Calls 3

fragmented_hypercubeFunction · 0.85
randnMethod · 0.45
qrMethod · 0.45

Tested by

no test coverage detected