Random numbers from aGrUM

These functions use the aGrUM’s peuso-random number generator (mt19937)from pyAgrum. It produces 32-bit pseudo-random numbers using the well-known and popular algorithm named Mersenne twister algorithm. mt19937 stands for m`ersenne `t`wister with a long period of 2`19937 – 1 which means mt19937 produces a sequence of 32-bit integers that only repeats itself after 219937 – 1 number have been generated.

Random functions

pyAgrum.initRandom(seed=0)

Initialize random generator seed. If seed=0, the generator is initialized from the current time in ms. seed!=0 allows to fix the generator in a certain stage and then allows to repeat the same pseudo-random numbers sequence.

Parameters:

seed (int) – the seed used to initialize the random generator (0 if using time)

Return type:

None

pyAgrum.randomProba()
Returns:

a random number between 0 and 1 included (i.e. a proba).

Return type:

float

pyAgrum.randomDistribution(n)
Parameters:

n (int) – The number of modalities for the ditribution.

Return type:

a random discrete distribution.

pyAgrum.generateSample(bn, n=1, name_out=None, show_progress=False, with_labels=True, random_order=True)

generate a CSV file of samples from a bn.

Parameters:
  • bn (pyAgrum.BayesNet) – the Bayes Net from which the sample is generated

  • n (int) – the number of samples

  • name_out (str) – the name for the output csv filename. If name_out is None, a pandas.DataFrame is generated

  • show_progress (bool) – if True, show a progress bar. Default is False

  • with_labels (bool) – if True, use the labels of the modalities of variables in the csv. If False, use their ids. Default is True

  • random_order (bool) – if True, the columns in the csv are randomized sorted. Default is True

Returns:

the log2-likelihood of the generated base or if name_out is None, the couple (generated pandas.DataFrame,log2-likelihood)

Return type:

float|Tuple[pandas.DataFrame,float]

pyAgrum.randomBN(*, n=5, names=None, ratio_arc=1.2, domain_size=2)

Creates a random BN using the (forced) keyword parameters. This function use pyAgrum.BNGenerator but the random variables will be named w.r.t. a topological order.

Warning

Number of nodes given with arg n`or `names must be bigger than 4, in order to be consistant

Examples

>>> bn=pyAgrum.randomBN()
>>> bn=pyAgrum.randomBN(n=10)
>>> bn=pyAgrum.randomBN(names="ABCDEF")
>>> bn=pyAgrum.randomBN(names=["Asia","Tuberculosis","Smoking"],ratio_arc=1.5,domain_size=3)

Warning

This function has only keyword parameters (no positional).

Parameters:
  • n (int) – number of nodes

  • names (List[str]) – list of names

  • ratio_arc (float) – number of arcs = n * ratio_arc

  • domain_size (int) – the domain size for the variables.

Return type:

BayesNet

Returns:

pyAgrum.BayesNet