BNGenerator.generate

BNGenerator.generate(n_nodes=10, n_arcs=15, n_modmax=4)

Generate a new Bayesian network.

The DAG is connected, with at most n_arcs arcs; each variable has a domain size drawn uniformly between 2 and n_modmax; each distribution of a CPT (one per configuration of the parents) is drawn uniformly on the probability simplex, i.e. from a Dirichlet distribution of parameter 1.

Parameters:
  • n_nodes (int) – the number of nodes (default=10)

  • n_arcs (int) – the maximum number of arcs (default=15)

  • n_modmax (int) – the max number of modalities for a node (default=4)

Returns:

the generated Bayesian network

Return type:

pyagrum.BayesNet

Raises:

Example

import pyagrum as gum

gum.initRandom(42)
generator = gum.BNGenerator()
bn = generator.generate(n_nodes=6, n_arcs=8, n_modmax=3)  # at most 8 arcs
bn.size(), bn.sizeArcs()
# (6, 6)
bn.maxVarDomainSize() <= 3
# True

Class

BNGenerator