Skip to content

Random generation of Bayesian network

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

Section titled “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

BNGenerator is used to easily generate Bayesian networks.

BNGenerator() -> BNGenerator : default constructor

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

Section titled “generate(n_nodes=10, n_arcs=15, n_modmax=4)”

Generate a new Bayesian network

  • Parameters:
    • n_nodes (int) – the number of nodes (default=10)
    • n_arcs (int) – the number of arcs (default=15)
    • n_nodmax (int) – the max number of modalities for a node (default=4)
    • n_modmax (int)
  • Returns: the generated Bayesian network
  • Return type: pyagrum.BayesNet
  • Raises: