-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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
PolytopeNoiseorPolytopewith something like "To get deterministic behavior, callnp.random.seed(0)before instantiating Polytope". - Or change
PolytopeNoiseso that it uses a deterministic order of the polytope's vertices.
I'll create a pull request for the 2nd option.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels