When using the new `Generator`s for stochastic optimisation I sometimes find myself possessing a great solution, but am wondering what path the random number generation took to get to that point. I know that I can get the current state of the BitGenerators. However, what I'd like to do is query the BitGenerator to figure out how the BitGenerator was setup in the first place. i.e. either: - the seed/SeedSequence that was used to construct the BitGenerator or - the state that was last applied to the BitGenerator One obvious way around this would be to do the seeding in the first place, but it would sure be nice to figure out how to replicate the BitGenerator without having to do that. I'm thinking of something like: ``` rng = np.random.default_rng(190828902908) rng.uniform(size=(100,)) # 190828902908 print(rng.initial_seed) ``` -- _____________________________________ Dr. Andrew Nelson _____________________________________
On Fri, Aug 2, 2024 at 1:28 AM Andrew Nelson <andyfaff@gmail.com> wrote:
When using the new `Generator`s for stochastic optimisation I sometimes find myself possessing a great solution, but am wondering what path the random number generation took to get to that point.
I know that I can get the current state of the BitGenerators. However, what I'd like to do is query the BitGenerator to figure out how the BitGenerator was setup in the first place.
i.e. either:
- the seed/SeedSequence that was used to construct the BitGenerator
rng = np.random.default_rng() rng.bit_generator.seed_seq SeedSequence( entropy=186013007116029215180532390504704448637, )
In some older versions of numpy, the attribute was semi-private as _seed_seq, if you're still using one of those. -- Robert Kern
On Fri, Aug 2, 2024 at 9:37 AM Robert Kern <robert.kern@gmail.com> wrote:
On Fri, Aug 2, 2024 at 1:28 AM Andrew Nelson <andyfaff@gmail.com> wrote:
When using the new `Generator`s for stochastic optimisation I sometimes find myself possessing a great solution, but am wondering what path the random number generation took to get to that point.
I know that I can get the current state of the BitGenerators. However, what I'd like to do is query the BitGenerator to figure out how the BitGenerator was setup in the first place.
i.e. either:
- the seed/SeedSequence that was used to construct the BitGenerator
rng = np.random.default_rng() rng.bit_generator.seed_seq SeedSequence( entropy=186013007116029215180532390504704448637, )
In some older versions of numpy, the attribute was semi-private as _seed_seq, if you're still using one of those.
In many cases you can add your own attributes to python objects, so you can record the seed yourself as rng.my_seed = blah
I didn't test if the BitGenerator supports this -- *Those who don't understand recursion are doomed to repeat it*
- the seed/SeedSequence that was used to construct the BitGenerator
rng = np.random.default_rng() rng.bit_generator.seed_seq SeedSequence( entropy=186013007116029215180532390504704448637, )
In some older versions of numpy, the attribute was semi-private as _seed_seq, if you're still using one of those.
This is exactly what I was looking for.
participants (3)
-
Andrew Nelson
-
Neal Becker
-
Robert Kern