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
Section titled “class pyagrum.JunctionTreeGenerator”JunctionTreeGenerator is use to generate junction tree or binary junction tree from Bayesian networks.
JunctionTreeGenerator() -> JunctionTreeGenerator : default constructor
binaryJoinTree(*args)
Section titled “binaryJoinTree(*args)”Computes the binary joint tree for its parameters. If the first parameter is a graph, the heurisitcs assume that all the node have the same domain size (2). If given, the heuristic takes into account the partial order for its elimination order.
- Parameters:
- g (pyagrum.UndiGraph) – a undirected graph
- dag (pyagrum.DAG) – a dag
- bn (pyagrum.BayesNet) – a BayesianNetwork
- partial_order (list of list of int) – a partial order among the nodeIDs
- Returns: the current binary joint tree
- Return type: pyagrum.CliqueGraph
eliminationOrder(*args)
Section titled “eliminationOrder(*args)”Computes the elimination for its parameters. If the first parameter is a graph, the heurisitcs assume that all the node have the same domain size (2). If given, the heuristic takes into account the partial order for its elimination order.
- Parameters:
- g (pyagrum.UndiGraph) – a undirected graph
- dag (pyagrum.DAG) – a dag
- bn (pyagrum.BayesNet) – a BayesianNetwork
- partial_order (list of list of int) – a partial order among the nodeIDs
- Returns: the current elimination order.
- Return type:
list[int]
junctionTree(*args)
Section titled “junctionTree(*args)”Computes the junction tree for its parameters. If the first parameter is a graph, the heurisitcs assume that all the node have the same domain size (2). If given, the heuristic takes into account the partial order for its elimination order.
- Parameters:
- g (pyagrum.UndiGraph) – a undirected graph
- dag (pyagrum.DAG) – a dag
- bn (pyagrum.BayesNet) – a BayesianNetwork
- partial_order (list of list of int) – a partial order among the nodeIDs
- Returns: the current junction tree.
- Return type: pyagrum.CliqueGraph
class pyagrum.EssentialGraph(*args)
Section titled “class pyagrum.EssentialGraph(*args)”Class building the essential graph from a BN.
Essential graph is a mixed graph (Chain Graph) that represents the class of markov equivalent Bayesian networks (with the same independency model).
EssentialGraph(m) -> EssentialGraph : Parameters: : - m (pyagrum.DAGmodel) – a DAGmodel
adjacencyMatrix()
Section titled “adjacencyMatrix()”adjacency matrix from a graph/graphical models
Compute the adjacency matrix of a pyAgrum’s graph or graphical models (more generally an object that has nodes, children/parents or neighbours methods)
- Returns: adjacency matrix (as numpy.ndarray) with nodeId as key.
- Return type: numpy.ndarray
ancestors(*args)
Section titled “ancestors(*args)”give the set of nodeid of ancestors of a node
- Parameters: norid (str *|*int) – the name or the id of the node
- Returns: the set of ids of the ancestors of node norid.
- Return type:
list[int]
arcs()
Section titled “arcs()”- Returns: The lisf of arcs in the EssentialGraph
- Return type:
set[tuple[int,int]]
children(id)
Section titled “children(id)”- Parameters:
id (
int) – the id of the parent - Returns: the set of all the children
- Return type:
list[int]
connectedComponents()
Section titled “connectedComponents()”Return the connected components of the essential graph.
Each node is mapped to the id of its component root (an arbitrarily chosen node from the same component).
- Returns: mapping node id → component root id
- Return type:
dict[int,int]
connectedComponentsCount()
Section titled “connectedComponentsCount()”number of connected components
- Returns: the number of connected components in the graph.
- Return type: int
connectedComponentsList()
Section titled “connectedComponentsList()”connected components as a dict of sets
- Returns: dict of connected components (as sets of nodeIds) keyed by an arbitrary root nodeId per component.
- Return type: dict(int, set[int])
descendants(*args)
Section titled “descendants(*args)”give the set of nodeid of descendants of a node
- Parameters: norid (str *|*int) – the name or the id of the node
- Returns: the set of ids of the descendants of node norid.
- Return type:
list[int]
edges()
Section titled “edges()”- Returns: the list of the edges
- Return type:
set[tuple[int,int]]
idFromName(name)
Section titled “idFromName(name)”- Parameters:
name (
str) – the name of the variable in the model - Returns: the nodeId from the name of the variable in the model
- Return type:
int
nameFromId(node)
Section titled “nameFromId(node)”- Parameters:
node (
int) – the nodeId of the variable in the model - Returns: the name of the variable in the model from the nodeId
- Return type:
str
neighbours(id)
Section titled “neighbours(id)”- Parameters:
id (
int) – the id of the checked node - Returns: The set of edges adjacent to the given node
- Return type:
list[int]
nodes()
Section titled “nodes()”Return the set of node ids in the essential graph.
- Returns: the set of all node ids
- Return type:
set[int]
parents(id)
Section titled “parents(id)”- Parameters:
id (
int) – The id of the child node - Returns: the set of the parents ids.
- Return type:
list[int]
pdag()
Section titled “pdag()”- Returns: the PDAG (Partially Directed Graph)
- Return type:
PDAG
size()
Section titled “size()”- Returns: the number of nodes in the graph
- Return type:
int
sizeArcs()
Section titled “sizeArcs()”- Returns: the number of arcs in the graph
- Return type:
int
sizeEdges()
Section titled “sizeEdges()”- Returns: the number of edges in the graph
- Return type:
int
sizeNodes()
Section titled “sizeNodes()”- Returns: the number of nodes in the graph
- Return type:
int
skeleton()
Section titled “skeleton()”Return the skeleton of the essential graph (the underlying undirected graph without arc orientations).
- Returns: the skeleton of the essential graph
- Return type:
UndiGraph
toDot()
Section titled “toDot()”- Returns: a friendly display of the graph in DOT format
- Return type:
str
class pyagrum.MarkovBlanket(*args)
Section titled “class pyagrum.MarkovBlanket(*args)”Class building the Markov blanket of a node in a graph.
MarkovBlanket(m,n) -> MarkovBlanket : Parameters: : - m (pyagrum.DAGmodel) – a DAGmodel - n (int) – a node id
MarkovBlanket(m,name) -> MarkovBlanket : Parameters: : - m (pyagrum.DAGmodel) – a DAGmodel - name (str) – a node name
adjacencyMatrix()
Section titled “adjacencyMatrix()”adjacency matrix from a graph/graphical models
Compute the adjacency matrix of a pyAgrum’s graph or graphical models (more generally an object that has nodes, children/parents or neighbours methods)
- Returns: adjacency matrix (as numpy.ndarray) with nodeId as key.
- Return type: numpy.ndarray
ancestors(*args)
Section titled “ancestors(*args)”give the set of nodeid of ancestors of a node
- Parameters: norid (str *|*int) – the name or the id of the node
- Returns: the set of ids of the ancestors of node norid.
- Return type:
list[int]
arcs()
Section titled “arcs()”- Returns: the list of the arcs
- Return type:
set[tuple[int,int]]
children(id)
Section titled “children(id)”- Parameters:
id (
int) – the id of the parent - Returns: the set of all the children
- Return type:
list[int]
connectedComponentsCount()
Section titled “connectedComponentsCount()”number of connected components
- Returns: the number of connected components in the graph.
- Return type: int
connectedComponentsList()
Section titled “connectedComponentsList()”connected components as a dict of sets
- Returns: dict of connected components (as sets of nodeIds) keyed by an arbitrary root nodeId per component.
- Return type: dict(int, set[int])
- Returns: a copy of the DAG
- Return type:
DAG
descendants(*args)
Section titled “descendants(*args)”give the set of nodeid of descendants of a node
- Parameters: norid (str *|*int) – the name or the id of the node
- Returns: the set of ids of the descendants of node norid.
- Return type:
list[int]
hasSameStructure(other)
Section titled “hasSameStructure(other)”- Parameters: pyagrum.DAGmodel – a direct acyclic model
- Returns: True if all the named node are the same and all the named arcs are the same
- Return type: bool
nodes()
Section titled “nodes()”- Returns: the set of ids
- Return type:
set[int]
parents(id)
Section titled “parents(id)”- Parameters:
id (
int) – The id of the child node - Returns: the set of the parents ids.
- Return type:
list[int]
size()
Section titled “size()”- Returns: the number of nodes in the graph
- Return type:
int
sizeArcs()
Section titled “sizeArcs()”- Returns: the number of arcs in the graph
- Return type:
int
sizeNodes()
Section titled “sizeNodes()”- Returns: the number of nodes in the graph
- Return type:
int
toDot()
Section titled “toDot()”- Returns: a friendly display of the graph in DOT format
- Return type:
str