Explanation and analysis
This tools aimed to provide some different views on the Bayesian network in order to explore its qualitative and/or quantitave behaviours.
- class pyagrum.JunctionTreeGenerator
JunctionTreeGenerator is used to generate the junction tree, the binary join tree or the elimination order of a graph, a Bayesian network or a Markov random field.
- JunctionTreeGenerator() -> JunctionTreeGenerator
default constructor
Scientific notes
JunctionTreeGenerator builds the junction trees of the exact inferences (described in pyagrum.LazyPropagation),
for a graph given by the user: the moral graph of a Bayesian network or of a DAG (the parents of each node are linked
and the arcs become edges), the graph of a Markov random field, or an undirected graph, is triangulated by
eliminating its nodes one by one, each elimination linking the remaining neighbours of the node (the fill-ins); the
cliques created by the eliminations, minus those included in another one, are linked into a junction tree whose
separators are the intersections of adjacent cliques [1].
The elimination order (eliminationOrder) is the one of the default triangulation of pyAgrum (see
pyagrum.LazyPropagation): a greedy choice guided by the weight of a node, the product of the domain sizes of the
node and of its remaining neighbours, i.e. the size of the table of the clique that its elimination creates. The
domain sizes are those of the variables for a Bayesian network or a Markov random field; for a graph or a DAG, every
node counts for 2, so that the weight of a node only depends on its number of neighbours. With a partial order (a
list of sets of nodes, which must cover all the nodes), all the nodes of a set are eliminated before those of the
next one, the same rules choosing inside each set.
The binary join tree (binaryJoinTree) is the junction tree transformed so that no clique has more than three
neighbours [2]: around a clique with too many neighbours, new cliques are inserted, each one
joining two separators, the pair whose union has the smallest table being joined first.
Methods
Computes a binary join tree for its parameters: a join tree in which each clique has at most 3 neighbours. |
|
Computes an elimination order for its parameters. |
|
Computes a junction tree for its parameters. |
- class pyagrum.EssentialGraph(*args)
The essential graph of a Bayesian network: the CPDAG of its Markov equivalence class, with the names of its variables.
The essential graph (or completed PDAG) represents the Markov equivalence class of a Bayesian network: the Bayesian networks with the same independence model. Its arcs have the same orientation in all the Bayesian networks of the class; its undirected edges may have both orientations.
An EssentialGraph is a
pyagrum.CPDAG(immutable, with all its methods). The names of the nodes are stored in the essential graph: it does not depend on the model it was built from.- EssentialGraph(m) -> EssentialGraph
- Parameters:
m (pyagrum.DAGmodel) – a Bayesian network (or any DAG model)
- EssentialGraph(m, pdag) -> EssentialGraph
- Parameters:
m (pyagrum.DAGmodel) – the model giving the names of the nodes
pdag (
pyagrum.PDAG) – the essential graph: it must be a CPDAG (pyagrum.InvalidArgumentotherwise)
- EssentialGraph(pdag) -> EssentialGraph
- Parameters:
pdag (
pyagrum.PDAG) – the essential graph, with the names of its nodes: it must be a CPDAG (pyagrum.InvalidArgumentotherwise)
- EssentialGraph(cpdag) -> EssentialGraph
- Parameters:
cpdag (
pyagrum.CPDAG) – the essential graph, with the names of its nodes
Scientific notes
The essential graph of a Bayesian network is the CPDAG of the Markov equivalence class of its DAG
[3]: its arcs are the compelled ones, which have the same orientation in all the DAGs
of the class, and its undirected edges the reversible ones. Built from a model, it is computed by the algorithm
Find-Compelled of [4]; built from a PDAG, the PDAG is checked to be a CPDAG. Its
characterization and its separation are those of pyagrum.CPDAG; it only adds the names of the variables, kept in the
graph, so that it does not depend on the model it was built from.
Steen A. Andersson, David Madigan, and Michael D. Perlman. A characterization of Markov equivalence classes for acyclic digraphs. The Annals of Statistics, 25(2):505–541, 1997. URL: https://projecteuclid.org/journals/annals-of-statistics/volume-25/issue-2/A-characterization-of-Markov-equivalence-classes-for-acyclic-digraphs/10.1214/aos/1031833662.full, doi:10.1214/aos/1031833662.
David Maxwell Chickering. A transformational characterization of equivalent Bayesian network structures. In Proceedings of the Eleventh Conference on Uncertainty in Artificial Intelligence (UAI 1995), 87–98. 1995. URL: https://arxiv.org/abs/1302.4938.
Methods
give the set of nodeid of ancestors of a node |
|
give the set of nodeid of descendants of a node |
|
Save the graph as a .jgum (text) or .bgum (binary) file (its class, its nodes with their names, its arcs, edges and marks). |
|
Save the graph as a jgum string (see |
|
Drawn as a |
Methods inherited from CPDAG
adjacency matrix from a graph/graphical models |
|
The connected components of the graph (of its skeleton). |
|
number of connected components |
|
connected components as a dict of sets |
|
Check if the sets of nodes X and Y are d-separated (by the set of nodes Z if given) in every DAG represented by the CPDAG. |
|
The CPDAG of the Markov equivalence class of a DAG (algorithm Find-Compelled of Chickering 1995). |
|
Checked conversion of a PDAG into a CPDAG: the PDAG must be the CPDAG of its consistent extensions. |
|
Return the id of the node with the given name, or None if no such name exists. |
|
The ids of nodes given by their names, in a container of the same type. |
|
Return the name of a node, or its id as a string if no name was set. |
|
The names of nodes given by their ids, in a container of the same type. |
|
- class pyagrum.MarkovBlanket(*args)
Class building the Markov blanket of a node in a graph.
The Markov blanket of level 1 of a node contains the node, its parents, its children and the other parents of its children. The Markov blanket of level k > 1 adds the Markov blankets of level 1 of the nodes added at level k-1 (the construction stops early when no new node is found).
- MarkovBlanket(m,n,level=1) -> MarkovBlanket
- Parameters:
m (pyagrum.DAGmodel) – a DAGmodel
n (int) – a node id
level (int) – the level of the Markov blanket (at least 1)
- MarkovBlanket(m,name,level=1) -> MarkovBlanket
- Parameters:
m (pyagrum.DAGmodel) – a DAGmodel
name (str) – a node name
level (int) – the level of the Markov blanket (at least 1)
- Raises:
pyagrum.InvalidArgument – If
levelis lower than 1, or if the id is not a node of the model.pyagrum.NotFound – If no node has this name.
Scientific notes
The Markov blanket of a node \(X\) of a Bayesian network is the set of its parents, its children and the other
parents of its children: given its blanket, \(X\) is independent of all the other variables
[5]. MarkovBlanket returns it as a DAG made of \(X\), its blanket, the arcs into
\(X\), out of \(X\) and into its children, plus the other arcs of the model between the nodes of the blanket
(from a parent to a co-parent, for instance), which toDot draws in grey.
With level \(k > 1\) (an extension of pyAgrum), the same construction is repeated from the nodes added at the
previous level, \(k\) times or until no node is added: level 2 adds the parents, children and co-parents of the
nodes of the blanket.
Judea Pearl. Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference. Morgan Kaufmann, 1988. URL: https://doi.org/10.1016/C2009-0-27609-4, doi:10.1016/C2009-0-27609-4.
Methods
adjacency matrix from a graph/graphical models |
|
give the set of nodeid of ancestors of a node |
|
give the set of nodeid of descendants of a node |
|
The ids of nodes given by their names, in a container of the same type. |
|
The names of nodes given by their ids, in a container of the same type. |
|