Fragment of Bayesian networks

This class proposes a shallow copy of a part of Bayesian network. It can be used as a Bayesian network for inference algorithms (for instance).

class pyagrum.BayesNetFragment(bn)

BayesNetFragment represents a part of a Bayesian network (subset of nodes). By default, the arcs and the CPTs are the same as the BN but local CPTs can be build to express different local dependencies. All the non local CPTs are not copied. Therefore a BayesNetFragment is a light object.

BayesNetFragment(BayesNet bn) -> BayesNetFragment
Parameters:
Parameters:

bn (IBayesNet)

Methods

addStructureListener()

Add the listeners in parameters to the list of existing ones.

adjacencyMatrix()

adjacency matrix from a graph/graphical models

ancestors()

give the set of nodeid of ancestors of a node

arcs()

check()

Check if the BayesNet is consistent (variables, CPT, …)

checkConsistency()

If a variable is added to the fragment but not its parents, there is no CPT consistant for this variable.

children()

give the set of nodeid of the children of a node (or of a set of nodes)

completeInstantiation()

Give an instantiation over all the variables of the model

connectedComponents()

Return the weakly connected components of the graph.

connectedComponentsCount()

number of connected components

connectedComponentsList()

connected components as a dict of sets

cpt()

Returns the CPT of a variable.

dag()

descendants()

give the set of nodeid of descendants of a node

dim()

Returns the dimension (the number of free parameters) in this BayesNet.

empty()

Check if there are some variables in the model.

evEq()

This method is used to set an observation on a quasi-continuous variables (pyagrum.DiscretizedVariable with a large number of ticks) that the variable is equal to a given value.

evGt()

This method is used to set an observation on a quasi-continuous variables (pyagrum.DiscretizedVariable with a large number of ticks) that the variable is greater than a given value.

evIn()

This method is used to set an observation on a quasi-continuous variables (pyagrum.DiscretizedVariable with a large number of ticks) that the variable is in a given range.

evLt()

This method is used to set an observation on a quasi-continuous variables (pyagrum.DiscretizedVariable with a large number of ticks) that the variable is less than a given value.

exists()

Check if a node with this name or id exists

existsArc()

Check if an arc exists

existsProperty()

Check whether a property key exists in the model’s metadata.

family()

give the set of parents of a node and the node

hasSameStructure()

idFromName()

Returns a variable’s id given its name in the graph.

ids()

List of ids for a list of names of variables in the model

idsFromNames()

The ids of nodes given by their names, in a container of the same type.

installAscendants()

Add the variable and all its ascendants in the fragment.

installCPT()

Install a local CPT for a node.

installMarginal()

Install a local marginal for a node.

installNode()

Add a node to the fragment.

isIndependent()

check if nodes X and nodes Y are independent given nodes Z

isInstalledNode()

Check if a node is in the fragment

jointProbability()

log10DomainSize()

returns the log10 of the domain size of the model defined as the product of the domain sizes of the variables in the model.

log2JointProbability()

maxNonOneParam()

maxParam()

maxVarDomainSize()

memoryFootprint()

Returns the memory footprint in bytes of the Bayesian network.

minNonZeroParam()

minParam()

minimalCondSet()

Returns, given one or many targets and a list of variables, the minimal set of those needed to calculate the target/targets.

moralGraph()

Returns the moral graph of the BayesNet, formed by adding edges between all pairs of nodes that have a common child, and then making all edges in the graph undirected.

moralizedAncestralGraph()

build a UndiGraph by moralizing the Ancestral Graph of a list of nodes

names()

Set of names of variables in the model

namesFromIds()

The names of nodes given by their ids, in a container of the same type.

nodeId()

nodes()

nodeset()

Set of ids for a list of names of variables in the model

parents()

give the set of nodeid of the parents of a node (or of a set of nodes)

properties()

Return the keys of all metadata properties of the model.

property()

Returns the value associated to this property.

propertyWithDefault()

Returns the value associated to this property or the default value if there is no such property.

setProperty()

Create or change the couple (name,value) in the properties.

size()

sizeArcs()

spaceCplxToString()

Return a human-readable string summarising the space complexity of a graphical model.

toBN()

Create a BayesNet from a fragment.

toDot()

topologicalOrder()

uninstallCPT()

Remove a local CPT.

uninstallNode()

Remove a node from the fragment.

updateMetaData()

Update the model’s built-in metadata (version, creation date, last modification date).

variable()

variableFromName()

variables()

Return the variables of the model: all of them, or those corresponding to a list of names or to a set of node ids.