Random numbers from aGrUM
These functions use the pseudo-random number generator of aGrUM (mt19937). It produces 32-bit pseudo-random numbers with the Mersenne twister algorithm: mt19937 stands for Mersenne twister with a period of 219937 − 1, which means that the sequence of 32-bit integers only repeats itself after 219937 − 1 numbers have been generated.
Random functions
Initialize random generator seed. |
|
Give the seed of the pseudo-random generator, to replay a sequence of draws. |
|
A numpy random generator driven by the random generator of aGrUM. |
|
Draws a value of the Gamma distribution of shape |
|
Shuffle a sequence in place with the random generator of pyAgrum. |
|
generate a CSV file of samples from a bn. |
|
Creates a random BN using the (forced) keyword parameters. |
Reproducible block of code
- class pyagrum.RandomGeneratorGuard
Saves the state of the pseudo-random generator of pyAgrum and restores it later: a block of code can call
pyagrum.initRandomand draw without changing the sequence of draws of the rest of the program.The state (and the seed given by
pyagrum.randomGeneratorSeed) is saved when the guard is created, and restored bypyagrum.RandomGeneratorGuard.restore, or at the end of awithblock, even if it is left by an exception. After the restoration, the draws are the ones that would have followed the creation of the guard.RandomGeneratorGuard() -> RandomGeneratorGuard
Notes
The generator is shared by the whole library and is not thread safe: the guard is meant for a sequential block of code.
Methods
Restore the seed and the state of the generator saved when the guard was created. |