Inference for Influence Diagram

an inference in an influence diagram
class pyagrum.ShaferShenoyLIMIDInference(infDiag)

This inference considers the provided model as a LIMID rather than an influence diagram. It is an optimized implementation of the LIMID resolution algorithm. However an inference on a classical influence diagram can be performed by adding a assumption of the existence of the sequence of decision nodes to be solved, which also implies that the decision choices can have an impact on the rest of the sequence (Non Forgetting Assumption, cf. pyagrum.ShaferShenoyLIMIDInference.addNoForgettingAssumption).

Parameters:

infDiag (InfluenceDiagram)

MEU(*args)

Returns maximum expected utility obtained from inference.

Raises:

pyagrum.OperationNotAllowed – If no inference have yet been made

Return type:

dict[str, float]

addEvidence(*args)

Adds a new evidence on a node (might be soft or hard).

Parameters:
  • id (int) – a node Id

  • nodeName (int) – a node name

  • val – (int) a node value

  • val – (str) the label of the node value

  • vals (list) – a list of values

Raises:
Return type:

None

addNoForgettingAssumption(*args)

Add a no-forgetting assumption for a list of decision variables.

The no-forgetting assumption means that each decision node has access to all variables observed before it in the decision order.

Parameters:

ids (list[int]) – the list of decision node ids

Raises:

pyagrum.InvalidArgument – if a given id is not a decision node

Return type:

None

chgEvidence(*args)

Change the value of an already existing evidence on a node (might be soft or hard).

Parameters:
  • id (int) – a node Id

  • nodeName (int) – a node name

  • val (int|str) – a node value or the label of the node value

  • vals (list of float) – a list of values

Raises:
Return type:

None

clear()

Clear all evidence and reset the inference engine to its initial state.

Return type:

None

eraseAllEvidence()

Remove all evidence.

Return type:

None

eraseEvidence(*args)

Remove the evidence, if any, corresponding to the node Id or name.

Parameters:
  • id (int) – a node Id

  • nodeName (int) – a node name

Raises:

pyagrum.IndexError – If the node does not belong to the Bayesian network

Return type:

None

hardEvidenceNodes()
Returns:

the set of nodes with hard evidence

Return type:

set

hasEvidence(*args)
Parameters:
  • id (int) – a node Id

  • nodeName (str) – a node name

Returns:

True if some node(s) (or the one in parameters) have received evidence

Return type:

bool

Raises:

pyagrum.IndexError – If the node does not belong to the Bayesian network

hasHardEvidence(nodeName)
Parameters:
  • id (int) – a node Id

  • nodeName (str) – a node name

Returns:

True if node has received a hard evidence

Return type:

bool

Raises:

pyagrum.IndexError – If the node does not belong to the Bayesian network

hasNoForgettingAssumption()

Check whether the no-forgetting assumption has been added.

Returns:

True if the no-forgetting assumption is currently active

Return type:

bool

hasSoftEvidence(*args)
Parameters:
  • id (int) – a node Id

  • nodeName (str) – a node name

Returns:

True if node has received a soft evidence

Return type:

bool

Raises:

pyagrum.IndexError – If the node does not belong to the Bayesian network

influenceDiagram()

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

Returns:

the InfluenceDiagram on which this class work

Return type:

pyagrum.InfluenceDiagram

isSolvable()

check wether the influence diagram is solvable or not

Returns:

True if the influence diagram is solvable

Return type:

bool

junctionTree()
Returns:

the current junction tree

Return type:

pyagrum.CliqueGraph

makeInference()

Perform the heavy computations needed to compute the optimal decisions.

Return type:

None

meanVar(*args)
Parameters:
  • id (int) – a node Id

  • nodeName (str) – a node name

Returns:

a dictionary with the mean and variance of the node (after the inference)

Return type:

dict[str, float]

nbrEvidence()
Returns:

the number of evidence entered into the Bayesian network

Return type:

int

nbrHardEvidence()
Returns:

the number of hard evidence entered into the Bayesian network

Return type:

int

nbrSoftEvidence()
Returns:

the number of soft evidence entered into the Bayesian network

Return type:

int

optimalDecision(*args)

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

Parameters:

decisionId (int,str) – the id or name of the decision variable

Raises:

pyagrum.OperationNotAllowed – If no inference have yet been made

Return type:

Tensor

pyagrum.InvalidNode

If node given in parmaeter is not a decision node

posterior(*args)

Returns the posterior of a chance or a decision node (after optimisation).

Parameters:
  • var (int) – the node Id of the node for which we need a posterior probability

  • nodeName (str) – the node name of the node for which we need a posterior probability

Returns:

a const ref to the posterior probability of the node

Return type:

pyagrum.Tensor

posteriorUtility(*args)

Returns the posterior utiliyt of a utility node (after optimisation) depending on decision nodes, if any.

Parameters:
  • var (int) – the node Id of the node for which we need a posterior probability

  • nodeName (str) – the node name of the node for which we need a posterior probability

Returns:

a const ref to the posterior utility of the utility node

Return type:

pyagrum.Tensor

reducedGraph()

Returns the DAG build to solve the influence diagram.

Returns:

a copy of the reduced graph

Return type:

pyagrum.DAG

reducedLIMID()

Returns the (reduced) LIMID build to solve the influence diagram.

Returns:

a copy of the reduced influence Diagram (LIMID)

Return type:

pyagrum.InfluenceDiagram

reversePartialOrder()

Return the reversed partial order of decision nodes used internally.

Returns:

the reversed partial order as a list of node id sets

Return type:

list[set[int]]

setEvidence(evidces)

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

Parameters:

evidces (dict) – a dict of evidences

Raises:
softEvidenceNodes()

Return the set of nodes with soft (likelihood) evidence.

Returns:

the set of node ids with soft evidence

Return type:

set[int]

updateEvidence(evidces)

Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).

Parameters:

evidces (dict) – a dict of evidences

Raises: