Random generation of Bayesian network
- 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:
- Returns:
pyAgrum.BayesNet
- class pyAgrum.BNGenerator
BNGenerator is used to easily generate Bayesian networks.
- BNGenerator() -> BNGenerator
default constructor
- 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:
- Raises:
pyAgrum.OperationNotAllowed – If n_modmax < 2
pyAgrum.OperationNotAllowed – If n_arcs is incompatible with n_nodes (not enough arcs)