Influence Diagram

Model

class pyAgrum.InfluenceDiagram(*args)

InfluenceDiagram represents an Influence Diagram.

Available ructors:

InfluenceDiagram() -> InfluenceDiagram

InfluenceDiagram(source) -> InfluenceDiagram

Parameters:source (pyAgrum.InfluenceDiagram) – the InfluenceDiagram to copy
add(self, variable, id=0)

add(self, variable) -> int

Add a chance variable, it’s associate node and it’s CPT.

The id of the new variable is automatically generated.

Parameters:
  • variable (pyAgrum.DiscreteVariable) – The variable added by copy.
  • id (int) – The chosen id. If 0, the NodeGraphPart will choose.

Warning

give an id (not 0) should be reserved for rare and specific situations !!!

Returns:the id of the added variable.
Return type:int
Raises:gum.DuplicateElement – If id(<>0) is already used
addArc(self, tail, head)

Add an arc in the ID, and update diagram’s potential nodes cpt if necessary.

Parameters:
  • tail (int) – the id of the tail node
  • head (int) – the id of the head node
Raises:
  • gum.InvalidEdge – If arc.tail and/or arc.head are not in the ID.
  • gum.InvalidEdge – If tail is a utility node
addChanceNode(self, variable, id=0)

addChanceNode(self, variable) -> int addChanceNode(self, variable, aContent, id=0) -> int addChanceNode(self, variable, aContent) -> int

Add a chance variable, it’s associate node and it’s CPT.

The id of the new variable is automatically generated.

Parameters:
  • variable (pyAgrum.DiscreteVariable) – the variable added by copy.
  • id (int) – the chosen id. If 0, the NodeGraphPart will choose.

Warning

give an id (not 0) should be reserved for rare and specific situations !!!

Returns:the id of the added variable.
Return type:int
Raises:gum.DuplicateElement – If id(<>0) is already used
addDecisionNode(self, variable, id=0)

addDecisionNode(self, variable) -> int

Add a decision variable.

The id of the new variable is automatically generated.

Parameters:
  • variable (pyAgrum.DiscreteVariable) – the variable added by copy.
  • id (int) – the chosen id. If 0, the NodeGraphPart will choose.

Warning

give an id (not 0) should be reserved for rare and specific situations !!!

Returns:the id of the added variable.
Return type:int
Raises:gum.DuplicateElement – If id(<>0) is already used
addUtilityNode(self, variable, id=0)

addUtilityNode(self, variable) -> int addUtilityNode(self, variable, aContent, id=0) -> int addUtilityNode(self, variable, aContent) -> int

Add a utility variable, it’s associate node and it’s UT.

The id of the new variable is automatically generated.

Parameters:
  • variable (pyAgrum.DiscreteVariable) – the variable added by copy
  • id (int) – the chosen id. If 0, the NodeGraphPart will choose

Warning

give an id (not 0) should be reserved for rare and specific situations !!!

Returns:

the id of the added variable.

Return type:

int

Raises:
  • gum.InvalidArgument – If variable has more than one label
  • gum.DuplicateElement – If id(<>0) is already used
arcs(self)
Returns:the list of all the arcs in the Influence Diagram.
Return type:list
chanceNodeSize(self)
Returns:the number of chance nodes.
Return type:int
changeVariableName(self, id, new_name)
Parameters:
  • id (int) – the node Id
  • new_name (str) – the name of the variable
Raises:
  • gum.DuplicateLabel – If this name already exists
  • gum.NotFound – If no nodes matches id.
children(self, id)
Parameters:id (int) – the id of the parent
Returns:the set of all the children
Return type:Set
completeInstantiation(self)

Get an instantiation over all the variables of the model.

Returns:the complete instantiation
Return type:pyAgrum.instantiation
cpt(self, varId)

Returns the CPT of a variable.

Parameters:VarId (int) – A variable’s id in the pyAgrum.BayesNet.
Returns:The variable’s CPT.
Return type:pyAgrum.Potential
Raises:gum.NotFound – If no variable’s id matches varId.
dag(self)
Returns:a ant reference to the dag of this BayesNet.
Return type:pyAgrum.DAG
decisionNodeSize(self)
Returns:the number of decision nodes
Return type:int
decisionOrderExists(self)
Returns:True if a directed path exist with all decision node
Return type:bool
empty(self)
Returns:True if the model is empty
Return type:bool
erase(self, id)

erase(self, var)

Erase a Variable from the network and remove the variable from all his childs.

If no variable matches the id, then nothing is done.

Parameters:
  • id (int) – The id of the variable to erase.
  • var (pyAgrum.DiscreteVariable) – The reference on the variable to remove.
eraseArc(self, arc)

eraseArc(self, tail, head)

Removes an arc in the ID, and update diagram’s potential nodes cpt if necessary.

If (tail, head) doesn’t exist, the nothing happens.

Parameters:
  • arc (pyAgrum.Arc) – The arc to be removed.
  • tail (int) – the id of the tail node
  • head (int) – the id of the head node
existsPathBetween(self, src, dest)
Returns:true if a path exists between two nodes.
Return type:bool
getDecisionGraph(self)
Returns:the temporal Graph.
Return type:pyAgrum.DAG
getDecisionOrder(self)
Returns:the sequence of decision nodes in the directed path.
Return type:list
Raises:NotFound – If such a path does not exist
hasSameStructure(self, 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
idFromName(self, name)

Returns a variable’s id given its name.

Parameters:name (str) – the variable’s name from which the id is returned.
Returns:the variable’s node id.
Return type:int
Raises:gum.NotFound – If no such name exists in the graph.
ids(self)

Note

Deprecated in pyAgrum>0.13.0 Please use nodes() instead

isChanceNode(self, varId)
Parameters:varId (int) – the tested node id.
Returns:true if node is a chance node
Return type:bool
isDecisionNode(self, varId)
Parameters:varId (int) – the tested node id.
Returns:true if node is a decision node
Return type:bool
isUtilityNode(self, varId)
Parameters:varId (int) – the tested node id.
Returns:true if node is an utility node
Return type:bool
loadBIFXML(self, name, l)

loadBIFXML(self, name) -> bool

Load a BIFXML file.

Parameters:

name (str) – the name’s file

Raises:
  • gum.IOError – If file not found
  • gum.FatalError – If file is not valid
log10DomainSize(self)
Returns:The log10 domain size of the joint probability for the model.
Return type:double
moralGraph(self, clear=True)

moralGraph(self) -> UndiGraph

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.

Returns:The moral graph
Return type:pyAgrum.UndiGraph
names(self)
Returns:The names of the InfluenceDiagram variables
Return type:list
nodeId(self, var)
Parameters:var (pyAgrum.DiscreteVariable) – a variable
Returns:the id of the variable
Return type:int
Raises:gum.IndexError – If the InfluenceDiagram does not contain the variable
nodes(self)
Returns:the set of ids
Return type:set
parents(self, id)
Parameters:id – The id of the child node
Returns:the set of the parents ids.
Return type:set
saveBIFXML(self, name)

Save the BayesNet in a BIFXML file.

Parameters:name (str) – the file’s name
size(self)
Returns:the number of nodes in the graph
Return type:int
sizeArcs(self)
Returns:the number of arcs in the graph
Return type:int
thisown

The membership flag

toDot(self)
Returns:a friendly display of the graph in DOT format
Return type:str
topologicalOrder(self, clear=True)

topologicalOrder(self) -> pyAgrum.Sequence< int >

Returns:the list of the nodes Ids in a topological order
Return type:List
Raises:gum.InvalidDirectedCycle – If this graph contains cycles
utility(self, varId)
Parameters:varId (int) – the tested node id.
Returns:the utility table of the node
Return type:pyAgrum.Potential
Raises:gum.IndexError – If the InfluenceDiagram does not contain the variable
utilityNodeSize(self)
Returns:the number of utility nodes
Return type:int
variable(self, id)
Parameters:id (int) – the node id
Returns:a ant reference over a variabe given it’s node id
Return type:pyAgrum.DiscreteVariable
Raises:gum.NotFound – If no variable’s id matches the parameter
variableFromName(self, name)
Parameters:name (str) – a variable’s name
Returns:the variable
Return type:pyAgrum.DiscreteVariable
Raises:gum.IndexError – If the InfluenceDiagram does not contain the variable
variableNodeMap(self)
Returns:the variable node map
Return type:pyAgrum.variableNodeMap

Inference

class pyAgrum.InfluenceDiagramInference(infDiag: pyAgrum.pyAgrum.InfluenceDiagram)

Proxy of C++ pyAgrum.InfluenceDiagramInference class. Proxy of C++ pyAgrum.InfluenceDiagramInference class.

displayResult(self)

Displays the result of an inference.

displayStrongJunctionTree(self, stream)

Displays on terminal the result of strong junction tree computation for test purpose only.

Parameters:args (TBW) –
eraseAllEvidence(self)

Removes all the evidence entered into the diagram.

eraseEvidence(self, evidence)
Parameters:evidence (pyAgrum.Potential) – the evidence to remove
Raises:gum.IndexError – If the evidence does not belong to the influence diagram
getBestDecisionChoice(self, decisionId)

Returns best choice for decision variable given in parameter ( based upon MEU criteria )

Parameters:

decisionId (int) – the id of the decision variable

Raises:
  • gum.OperationNotAllowed – If no inference have yet been made
  • gum.InvalidNode – If node given in parmaeter is not a decision node
getMEU(self)

Returns maximum expected utility obtained from inference.

Raises:gum.OperationNotAllowed – If no inference have yet been made
influenceDiagram(self)

Returns a ant reference over the InfluenceDiagram on which this class work.

Returns:the InfluenceDiagram on which this class work
Return type:pyAgrum.InfluenceDiagram
insertEvidence(self, evidenceList)

Insert new evidence in the graph.

Parameters:evidenceList (list) – a list of potentials as evidences

Warning

If an evidence already w.r.t. a given node and a new evidence w.r.t. this node is onserted, the old evidence is removed

Raises:gum.OperationNotAllowed – If an evidence is over more than one variable
junctionTreeToDot(self)
Returns:the result of strong junction tree computation for test purpose only.
Return type:str
makeInference(self)

Makes the inference.

setEvidence(evidces)

Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.

Parameters:

evidces (dict) – a dict of evidences

Raises:
  • gum.InvalidArgument – If one value is not a value for the node
  • gum.InvalidArgument – If the size of a value is different from the domain side of the node
  • gum.FatalError – If one value is a vector of 0s
  • gum.UndefinedElement – If one node does not belong to the Bayesian network
thisown

The membership flag