I wanted to get deterministic noise across runs. I tried the following:
import numpy as np
from ampyc.noise import PolytopeNoise
from ampyc.utils import Polytope
def get_unit_cube_polytope(noise_dim):
A = np.zeros((2 * noise_dim, noise_dim))
for i in range(noise_dim):
A[2 * i, i] = 1
A[2 * i + 1, i] = -1
b = np.ones((2 * noise_dim,))
return Polytope(A, b)
noise = PolytopeNoise(get_unit_cube_polytope(6))
noise.seed(5)
w = noise.generate()
However, this is not deterministic, as can be seen with this:
noise2 = PolytopeNoise(get_unit_cube_polytope(6))
noise2.seed(5)
w2 = noise2.generate()
assert not np.all(w == w2)
This is because Polytope.__init__() indirectly depends on np.random.rand() (via Polytope.__init__ > extreme > quickhull).
So after Polytope.__init__(), the order of vertices in self.V is non-deterministically random. But PolytopeNoise relies on the order of vertices in self.V. I find this counter-intuitive (I would have expected the above code to work).
Could you please do one of the following:
- Either document
PolytopeNoise or Polytope with something like "To get deterministic behavior, call np.random.seed(0) before instantiating Polytope".
- Or change
PolytopeNoise so that it uses a deterministic order of the polytope's vertices.
I'll create a pull request for the 2nd option.
I wanted to get deterministic noise across runs. I tried the following:
However, this is not deterministic, as can be seen with this:
This is because
Polytope.__init__()indirectly depends onnp.random.rand()(viaPolytope.__init__>extreme>quickhull).So after
Polytope.__init__(), the order of vertices inself.Vis non-deterministically random. ButPolytopeNoiserelies on the order of vertices inself.V. I find this counter-intuitive (I would have expected the above code to work).Could you please do one of the following:
PolytopeNoiseorPolytopewith something like "To get deterministic behavior, callnp.random.seed(0)before instantiating Polytope".PolytopeNoiseso that it uses a deterministic order of the polytope's vertices.I'll create a pull request for the 2nd option.