JunctionTreeGenerator.junctionTree
- JunctionTreeGenerator.junctionTree(*args)
Computes a junction tree for its parameters. The elimination order is chosen by heuristics that take the domain sizes into account and, if given, the partial order.
- Parameters:
g (
pyagrum.UndiGraph) – an undirected graph: all the nodes are given the same domain size (2)dag (
pyagrum.DAG) – a DAG, triangulated through its moral graph: all the nodes are given the same domain size (2)bn (
pyagrum.BayesNet) – a Bayesian network, triangulated through its moral graph, with the domain sizes of its variablesmrf (
pyagrum.MarkovRandomField) – a Markov random field, triangulated through its graph, with the domain sizes of its variablespartial_order (
list[set[int | str]], optional) – a partition of all the nodes into an ordered list of sets: the nodes of the first set are eliminated first, then those of the second set, and so on. The nodes are given by their ids, or by their names for a Bayesian network or a Markov random field.
- Raises:
pyagrum.NotFound – If the partial order does not contain all the nodes, or if a name is not the name of a variable.
pyagrum.InvalidArgument – If the partial order is not a sequence of sets of nodes.
- Returns:
the junction tree.
- Return type:
Example
import pyagrum as gum
bn = gum.fastBN("A->B->C<-D;A->D")
jt = gum.JunctionTreeGenerator().junctionTree(bn)
sorted(sorted(bn.variable(i).name() for i in jt.clique(c)) for c in jt.nodes())
# [['A', 'B', 'D'], ['B', 'C', 'D']]
Class