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(InfluenceDiagram self, DiscreteVariable variable, int id=0)

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(InfluenceDiagram self, int tail, int 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(InfluenceDiagram self, DiscreteVariable variable, int id=0)

addChanceNode(InfluenceDiagram self, DiscreteVariable variable, pyAgrum.MultiDimImplementation aContent, int id=0) -> 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(InfluenceDiagram self, DiscreteVariable variable, int id=0)

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(InfluenceDiagram self, DiscreteVariable variable, int id=0)

addUtilityNode(InfluenceDiagram self, DiscreteVariable variable, pyAgrum.MultiDimImplementation aContent, int id=0) -> 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(InfluenceDiagram self)
Returns:the list of all the arcs in the Influence Diagram.
Return type:list
chanceNodeSize(InfluenceDiagram self)
Returns:the number of chance nodes.
Return type:int
changeVariableName(InfluenceDiagram self, int id, str 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(InfluenceDiagram self, int id)
Parameters:id (int) – the id of the parent
Returns:the set of all the children
Return type:Set
completeInstantiation(DAGmodel self)

Get an instantiation over all the variables of the model.

Returns:the complete instantiation
Return type:pyAgrum.instantiation
cpt(InfluenceDiagram self, int 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(DAGmodel self)
Returns:a ant reference to the dag of this BayesNet.
Return type:pyAgrum.DAG
decisionNodeSize(InfluenceDiagram self)
Returns:the number of decision nodes
Return type:int
decisionOrderExists(InfluenceDiagram self)
Returns:True if a directed path exist with all decision node
Return type:bool
empty(DAGmodel self)
Returns:True if the model is empty
Return type:bool
erase(InfluenceDiagram self, int id)

erase(InfluenceDiagram self, DiscreteVariable 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(InfluenceDiagram self, Arc arc)

eraseArc(InfluenceDiagram self, int tail, int 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(InfluenceDiagram self, int src, int dest)
Returns:true if a path exists between two nodes.
Return type:bool
getDecisionGraph(InfluenceDiagram self)
Returns:the temporal Graph.
Return type:pyAgrum.DAG
getDecisionOrder(InfluenceDiagram self)
Returns:the sequence of decision nodes in the directed path.
Return type:list
Raises:NotFound – If such a path does not exist
hasSameStructure(DAGmodel self, DAGmodel 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(InfluenceDiagram self, str 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(InfluenceDiagram self)

Note

Deprecated in pyAgrum>0.13.0 Please use nodes() instead

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

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(DAGmodel self)
Returns:The log10 domain size of the joint probability for the model.
Return type:double
moralGraph(DAGmodel self, bool clear=True)

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(InfluenceDiagram self)
Returns:The names of the InfluenceDiagram variables
Return type:list
nodeId(InfluenceDiagram self, DiscreteVariable 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(DAGmodel self)
Returns:the set of ids
Return type:set
parents(InfluenceDiagram self, int id)
Parameters:id – The id of the child node
Returns:the set of the parents ids.
Return type:set
property(DAGmodel self, str name)

Warning

Unreferenced function

propertyWithDefault(DAGmodel self, str name, str byDefault)

Warning

Unreferenced function

saveBIFXML(InfluenceDiagram self, str name)

Save the BayesNet in a BIFXML file.

Parameters:name (str) – the file’s name
setProperty(DAGmodel self, str name, str value)

Warning

Unreferenced function

size(DAGmodel self)
Returns:the number of nodes in the graph
Return type:int
sizeArcs(DAGmodel self)
Returns:the number of arcs in the graph
Return type:int
toDot(InfluenceDiagram self)
Returns:a friendly display of the graph in DOT format
Return type:str
topologicalOrder(DAGmodel self, bool clear=True)
Returns:the list of the nodes Ids in a topological order
Return type:List
Raises:gum.InvalidDirectedCycle – If this graph contains cycles
utility(InfluenceDiagram self, int 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(InfluenceDiagram self)
Returns:the number of utility nodes
Return type:int
variable(InfluenceDiagram self, int 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(InfluenceDiagram self, str 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(DAGmodel 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(InfluenceDiagramInference self)

Displays the result of an inference.

displayStrongJunctionTree(InfluenceDiagramInference self, ostream stream=cout)

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

Parameters:args (TBW) –
eraseAllEvidence(InfluenceDiagramInference self)

Removes all the evidence entered into the diagram.

eraseEvidence(InfluenceDiagramInference self, Potential evidence)
Parameters:evidence (pyAgrum.Potential) – the evidence to remove
Raises:gum.IndexError – If the evidence does not belong to the influence diagram
getBestDecisionChoice(InfluenceDiagramInference self, int 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(InfluenceDiagramInference self)

Returns maximum expected utility obtained from inference.

Raises:gum.OperationNotAllowed – If no inference have yet been made
influenceDiagram(InfluenceDiagramInference 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(InfluenceDiagramInference self, pyAgrum.List< pyAgrum.Potential * > 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(InfluenceDiagramInference self)
Returns:the result of strong junction tree computation for test purpose only.
Return type:str
makeInference(InfluenceDiagramInference 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