Inference
Inference is the process that consists in computing new probabilistc information from a Bayesian network and some evidence. aGrUM/pyAgrum mainly focus on the computation of (joint) posterior for some variables of the Bayesian networks given soft or hard evidence that are the form of likelihoods on some variables. Inference is a hard task (NP-complete). aGrUM/pyAgrum implements exact inference but also approximated inference that can converge slowly and (even) not exactly but thant can in many cases be useful for applications.
Exact Inference
Section titled “Exact Inference”Lazy Propagation
Section titled “Lazy Propagation”Lazy Propagation is the main exact inference for classical Bayesian networks in aGrUM/pyagrum.
class pyagrum.LazyPropagation(*args)
Section titled “class pyagrum.LazyPropagation(*args)”Class used for Lazy Propagation
LazyPropagation(bn) -> LazyPropagation : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addJointTarget(targets)
Section titled “addJointTarget(targets)”Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
- Parameters:
- list – a list of names of nodes
- targets (
object)
- Raises: pyagrum.UndefinedElement – If some node(s) do not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllJointTargets()
Section titled “eraseAllJointTargets()”Clear all previously defined joint targets.
- Return type:
None
eraseAllMarginalTargets()
Section titled “eraseAllMarginalTargets()”Clear all the previously defined marginal targets.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseJointTarget(targets)
Section titled “eraseJointTarget(targets)”Remove, if existing, the joint target.
- Parameters:
- list – a list of names or Ids of nodes
- targets (
object)
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
evidenceJointImpact(*args)
Section titled “evidenceJointImpact(*args)”Create a pyagrum.Tensor for P(joint targets|evs) (for all instanciation of targets and evs)
- Parameters:
- targets (List [**intstr ]) – a list of node Ids or node names
- evs (Set [**intstr ]) – a set of nodes ids or names.
- Returns: a Tensor for P(target|evs)
- Return type: pyagrum.Tensor
- Raises: pyagrum.Exception – If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
evidenceProbability()
Section titled “evidenceProbability()”- Returns: the probability of evidence
- Return type: float
getNumberOfThreads()
Section titled “getNumberOfThreads()”returns the number of threads used by LazyPropagation during inferences.
- Returns: the number of threads used by LazyPropagation during inferences
- Return type: int
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
isGumNumberOfThreadsOverriden()
Section titled “isGumNumberOfThreadsOverriden()”Indicates whether LazyPropagation currently overrides aGrUM’s default number of threads (see method setNumberOfThreads).
- Returns: A Boolean indicating whether LazyPropagation currently overrides aGrUM’s default number of threads
- Return type: bool
isJointTarget(targets)
Section titled “isJointTarget(targets)”- Parameters:
- list – a list of nodes ids or names.
- targets (
object)
- Returns: True if target is a joint target.
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
joinTree()
Section titled “joinTree()”- Returns: the current join tree used
- Return type: pyagrum.CliqueGraph
jointMutualInformation(targets)
Section titled “jointMutualInformation(targets)”- Parameters:
targets (
object) - Return type:
float
jointPosterior(targets)
Section titled “jointPosterior(targets)”Compute the joint posterior of a set of nodes.
- Parameters: list – the list of nodes whose posterior joint probability is wanted
Warning
The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used by the Tensor.
- Returns: a const ref to the posterior joint probability of the set of nodes.
- Return type: pyagrum.Tensor
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
- Parameters:
targets (
object)
jointTargets()
Section titled “jointTargets()”- Returns: the list of target sets
- Return type: list
junctionTree()
Section titled “junctionTree()”- Returns: the current junction tree
- Return type: pyagrum.CliqueGraph
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
Find the Most Probable Explanation (MPE) given the evidence (if any) added into LazyPropagation
- Returns: An instantiation of all the variables of the Bayes net representing the Most Probable Explanation.
- Return type: pyagrum.Instantiation
mpeLog2Posterior()
Section titled “mpeLog2Posterior()”Find the Most Probable Explanation (MPE) given the evidence (if any) added into LazyPropagation as well as the log2 of its posterior probability
- Returns: A tuple with the instantiation of all the variables of the Bayes net representing the Most Probable Explanation and the log2 of its posterior probability
- Return type: Tuple[pyagrum.Instantiation, float]
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrJointTargets()
Section titled “nbrJointTargets()”- Returns: the number of joint targets
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxMemory(gigabytes)
Section titled “setMaxMemory(gigabytes)”sets an upper bound on the memory consumption admissible
- Parameters: gigabytes (float) – this upper bound in gigabytes.
- Return type:
None
setNumberOfThreads(nb)
Section titled “setNumberOfThreads(nb)”If the argument nb is different from 0, this number of threads will be used during inferences, hence overriding aGrUM’s default number of threads. If, on the contrary, nb is equal to 0, the parallelized inference engine will comply with aGrUM’s default number of threads.
- Parameters: nb (int) – the number of threads to be used by ShaferShenoyMRFInference
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
Shafer-Shenoy Inference
Section titled “Shafer-Shenoy Inference”class pyagrum.ShaferShenoyInference(*args)
Section titled “class pyagrum.ShaferShenoyInference(*args)”Class used for Shafer-Shenoy inferences.
ShaferShenoyInference(bn) -> ShaferShenoyInference : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addJointTarget(targets)
Section titled “addJointTarget(targets)”Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
- Parameters:
- list – a list of names of nodes
- targets (
object)
- Raises: pyagrum.UndefinedElement – If some node(s) do not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllJointTargets()
Section titled “eraseAllJointTargets()”Clear all previously defined joint targets.
- Return type:
None
eraseAllMarginalTargets()
Section titled “eraseAllMarginalTargets()”Clear all the previously defined marginal targets.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseJointTarget(targets)
Section titled “eraseJointTarget(targets)”Remove, if existing, the joint target.
- Parameters:
- list – a list of names or Ids of nodes
- targets (
object)
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
evidenceJointImpact(*args)
Section titled “evidenceJointImpact(*args)”Create a pyagrum.Tensor for P(joint targets|evs) (for all instanciation of targets and evs)
- Parameters:
- targets (List [**intstr ]) – a list of node Ids or node names
- evs (Set [**intstr ]) – a set of nodes ids or names.
- Returns: a Tensor for P(target|evs)
- Return type: pyagrum.Tensor
- Raises: pyagrum.Exception – If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
evidenceProbability()
Section titled “evidenceProbability()”- Returns: the probability of evidence
- Return type: float
getNumberOfThreads()
Section titled “getNumberOfThreads()”returns the number of threads used by LazyPropagation during inferences.
- Returns: the number of threads used by LazyPropagation during inferences
- Return type: int
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
isGumNumberOfThreadsOverriden()
Section titled “isGumNumberOfThreadsOverriden()”Indicates whether LazyPropagation currently overrides aGrUM’s default number of threads (see method setNumberOfThreads).
- Returns: A Boolean indicating whether LazyPropagation currently overrides aGrUM’s default number of threads
- Return type: bool
isJointTarget(targets)
Section titled “isJointTarget(targets)”- Parameters:
- list – a list of nodes ids or names.
- targets (
object)
- Returns: True if target is a joint target.
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
joinTree()
Section titled “joinTree()”- Returns: the current join tree used
- Return type: pyagrum.CliqueGraph
jointMutualInformation(targets)
Section titled “jointMutualInformation(targets)”- Parameters:
targets (
object) - Return type:
float
jointPosterior(targets)
Section titled “jointPosterior(targets)”Compute the joint posterior of a set of nodes.
- Parameters: list – the list of nodes whose posterior joint probability is wanted
Warning
The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used by the Tensor.
- Returns: a const ref to the posterior joint probability of the set of nodes.
- Return type: pyagrum.Tensor
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
- Parameters:
targets (
object)
jointTargets()
Section titled “jointTargets()”- Returns: the list of target sets
- Return type: list
junctionTree()
Section titled “junctionTree()”- Returns: the current junction tree
- Return type: pyagrum.CliqueGraph
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrJointTargets()
Section titled “nbrJointTargets()”- Returns: the number of joint targets
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxMemory(gigabytes)
Section titled “setMaxMemory(gigabytes)”sets an upper bound on the memory consumption admissible
- Parameters: gigabytes (float) – this upper bound in gigabytes.
- Return type:
None
setNumberOfThreads(nb)
Section titled “setNumberOfThreads(nb)”If the argument nb is different from 0, this number of threads will be used during inferences, hence overriding aGrUM’s default number of threads. If, on the contrary, nb is equal to 0, the parallelized inference engine will comply with aGrUM’s default number of threads.
- Parameters: nb (int) – the number of threads to be used by ShaferShenoyMRFInference
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
Variable Elimination
Section titled “Variable Elimination”class pyagrum.VariableElimination(*args)
Section titled “class pyagrum.VariableElimination(*args)”Class used for Variable Elimination inference algorithm.
Warning
Even if this inference has the same API than the other (exact) inferences, its mode of operation is different and is specifically dedicated to the calculation of a single posterior. Any other use (for instance for multiple targets) is possibly inefficient.
VariableElimination(bn) -> VariableElimination : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addJointTarget(targets)
Section titled “addJointTarget(targets)”Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
- Parameters:
- list – a list of names of nodes
- targets (
object)
- Raises: pyagrum.UndefinedElement – If some node(s) do not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseJointTarget(targets)
Section titled “eraseJointTarget(targets)”Remove, if existing, the joint target.
- Parameters:
- list – a list of names or Ids of nodes
- targets (
object)
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
evidenceJointImpact(targets, evs)
Section titled “evidenceJointImpact(targets, evs)”Create a pyagrum.Tensor for P(joint targets|evs) (for all instanciation of targets and evs)
- Parameters:
- targets (List [**intstr ]) – a list of node Ids or node names
- evs (Set [**intstr ]) – a set of nodes ids or names.
- Returns: a Tensor for P(target|evs)
- Return type: pyagrum.Tensor
- Raises: pyagrum.Exception – If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
getNumberOfThreads()
Section titled “getNumberOfThreads()”returns the number of threads used by LazyPropagation during inferences.
- Returns: the number of threads used by LazyPropagation during inferences
- Return type: int
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
isGumNumberOfThreadsOverriden()
Section titled “isGumNumberOfThreadsOverriden()”Indicates whether LazyPropagation currently overrides aGrUM’s default number of threads (see method setNumberOfThreads).
- Returns: A Boolean indicating whether LazyPropagation currently overrides aGrUM’s default number of threads
- Return type: bool
isJointTarget(targets)
Section titled “isJointTarget(targets)”- Parameters:
- list – a list of nodes ids or names.
- targets (
object)
- Returns: True if target is a joint target.
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
jointMutualInformation(targets)
Section titled “jointMutualInformation(targets)”- Parameters:
targets (
object) - Return type:
float
jointPosterior(targets)
Section titled “jointPosterior(targets)”Compute the joint posterior of a set of nodes.
- Parameters: list – the list of nodes whose posterior joint probability is wanted
Warning
The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used by the Tensor.
- Returns: a const ref to the posterior joint probability of the set of nodes.
- Return type: pyagrum.Tensor
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
- Parameters:
targets (
object)
jointTargets()
Section titled “jointTargets()”- Returns: the list of target sets
- Return type: list
junctionTree(id)
Section titled “junctionTree(id)”- Returns: the current junction tree
- Return type: pyagrum.CliqueGraph
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxMemory(gigabytes)
Section titled “setMaxMemory(gigabytes)”sets an upper bound on the memory consumption admissible
- Parameters: gigabytes (float) – this upper bound in gigabytes.
- Return type:
None
setNumberOfThreads(nb)
Section titled “setNumberOfThreads(nb)”If the argument nb is different from 0, this number of threads will be used during inferences, hence overriding aGrUM’s default number of threads. If, on the contrary, nb is equal to 0, the parallelized inference engine will comply with aGrUM’s default number of threads.
- Parameters: nb (int) – the number of threads to be used by ShaferShenoyMRFInference
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
Approximated Inference
Section titled “Approximated Inference”Loopy Belief Propagation
Section titled “Loopy Belief Propagation”class pyagrum.LoopyBeliefPropagation(bn)
Section titled “class pyagrum.LoopyBeliefPropagation(bn)”Class used for inferences using loopy belief propagation algorithm.
LoopyBeliefPropagation(bn) -> LoopyBeliefPropagation : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Sampling
Section titled “Sampling”Gibbs Sampling for BN
Section titled “Gibbs Sampling for BN”class pyagrum.GibbsSampling(bn)
Section titled “class pyagrum.GibbsSampling(bn)”Class for making Gibbs sampling inference in Bayesian networks.
GibbsSampling(bn) -> GibbsSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
burnIn()
Section titled “burnIn()”- Returns: size of burn in on number of iteration
- Return type: int
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isDrawnAtRandom()
Section titled “isDrawnAtRandom()”- Returns: True if variables are drawn at random
- Return type: bool
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrDrawnVar()
Section titled “nbrDrawnVar()”- Returns: the number of variable drawn at each iteration
- Return type: int
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setBurnIn(b)
Section titled “setBurnIn(b)”- Parameters: b (int) – size of burn in on number of iteration
- Return type:
None
setDrawnAtRandom(_atRandom)
Section titled “setDrawnAtRandom(_atRandom)”- Parameters: _atRandom (bool) – indicates if variables should be drawn at random
- Return type:
None
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setNbrDrawnVar(_nbr)
Section titled “setNbrDrawnVar(_nbr)”- Parameters: _nbr (int) – the number of variables to be drawn at each iteration
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Simple Monte Carlo Sampling for BN
Section titled “Simple Monte Carlo Sampling for BN”class pyagrum.MonteCarloSampling(bn)
Section titled “class pyagrum.MonteCarloSampling(bn)”Class used for Monte Carlo sampling inference algorithm.
MonteCarloSampling(bn) -> MonteCarloSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Weighted Sampling for BN
Section titled “Weighted Sampling for BN”class pyagrum.WeightedSampling(bn)
Section titled “class pyagrum.WeightedSampling(bn)”Class used for Weighted sampling inference algorithm.
WeightedSampling(bn) -> WeightedSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Importance Sampling for BN
Section titled “Importance Sampling for BN”class pyagrum.ImportanceSampling(bn)
Section titled “class pyagrum.ImportanceSampling(bn)”Class used for inferences using the Importance Sampling algorithm.
ImportanceSampling(bn) -> ImportanceSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Loopy sampling
Section titled “Loopy sampling”Pure Loopy Gibbs Sampling
Section titled “Pure Loopy Gibbs Sampling”class pyagrum.LoopyGibbsSampling(bn)
Section titled “class pyagrum.LoopyGibbsSampling(bn)”Class used for inferences using a loopy version of importance sampling.
LoopyImportanceSampling(bn) -> LoopyImportanceSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
burnIn()
Section titled “burnIn()”- Returns: size of burn in on number of iteration
- Return type: int
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isDrawnAtRandom()
Section titled “isDrawnAtRandom()”- Returns: True if variables are drawn at random
- Return type: bool
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
makeInference_()
Section titled “makeInference_()”- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrDrawnVar()
Section titled “nbrDrawnVar()”- Returns: the number of variable drawn at each iteration
- Return type: int
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setBurnIn(b)
Section titled “setBurnIn(b)”- Parameters: b (int) – size of burn in on number of iteration
- Return type:
None
setDrawnAtRandom(_atRandom)
Section titled “setDrawnAtRandom(_atRandom)”- Parameters: _atRandom (bool) – indicates if variables should be drawn at random
- Return type:
None
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setNbrDrawnVar(_nbr)
Section titled “setNbrDrawnVar(_nbr)”- Parameters: _nbr (int) – the number of variables to be drawn at each iteration
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
setVirtualLBPSize(vlbpsize)
Section titled “setVirtualLBPSize(vlbpsize)”- Parameters: vlbpsize (float) – the size of the virtual LBP
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Loopy Monte Carlo Sampling
Section titled “Loopy Monte Carlo Sampling”class pyagrum.LoopyMonteCarloSampling(bn)
Section titled “class pyagrum.LoopyMonteCarloSampling(bn)”Class used for inferences using a loopy version of importance sampling.
LoopyImportanceSampling(bn) -> LoopyImportanceSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
makeInference_()
Section titled “makeInference_()”- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
setVirtualLBPSize(vlbpsize)
Section titled “setVirtualLBPSize(vlbpsize)”- Parameters: vlbpsize (float) – the size of the virtual LBP
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Loopy Weighted Sampling
Section titled “Loopy Weighted Sampling”class pyagrum.LoopyWeightedSampling(bn)
Section titled “class pyagrum.LoopyWeightedSampling(bn)”Class used for inferences using a loopy version of importance sampling.
LoopyImportanceSampling(bn) -> LoopyImportanceSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
makeInference_()
Section titled “makeInference_()”- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
setVirtualLBPSize(vlbpsize)
Section titled “setVirtualLBPSize(vlbpsize)”- Parameters: vlbpsize (float) – the size of the virtual LBP
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool
Loopy Importance Sampling
Section titled “Loopy Importance Sampling”class pyagrum.LoopyImportanceSampling(bn)
Section titled “class pyagrum.LoopyImportanceSampling(bn)”Class used for inferences using a loopy version of importance sampling.
LoopyImportanceSampling(bn) -> LoopyImportanceSampling : Parameters: : - bn (pyagrum.BayesNet) – a Bayesian network
- Parameters:
bn (
IBayesNet)
- Returns: A constant reference over the IBayesNet referenced by this class.
- Return type: pyagrum.IBayesNet
- Raises: pyagrum.UndefinedElement – If no Bayes net has been assigned to the inference.
H(*args)
Section titled “H(*args)”- Parameters:
- X (int) – a node Id
- nodeName (str) – a node name
- Returns: the computed Shanon’s entropy of a node given the observation
- Return type: float
addAllTargets()
Section titled “addAllTargets()”Add all the nodes as targets.
- Return type:
None
addEvidence(*args)
Section titled “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:
- pyagrum.InvalidArgument – If the node already has an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
addTarget(*args)
Section titled “addTarget(*args)”Add a marginal target to the list of targets.
- Parameters:
- target (int) – a node Id
- nodeName (str) – a node name
- Raises: pyagrum.UndefinedElement – If target is not a NodeId in the Bayes net
- Return type:
None
chgEvidence(*args)
Section titled “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 (intstr) – a node value or the label of the node value
- vals (List [**float ]) – a list of values
- Raises:
- pyagrum.InvalidArgument – If the node does not already have an evidence
- pyagrum.InvalidArgument – If val is not a value for the node
- pyagrum.InvalidArgument – If the size of vals is different from the domain side of the node
- pyagrum.FatalError – If vals is a vector of 0s
- pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
currentPosterior(*args)
Section titled “currentPosterior(*args)”Computes and returns the current posterior of a node.
- 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 current posterior probability of the node
- Return type: pyagrum.Tensor
- Raises: UndefinedElement – If an element of nodes is not in targets
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type: float
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type: float
eraseAllEvidence()
Section titled “eraseAllEvidence()”Removes all the evidence entered into the network.
- Return type:
None
eraseAllTargets()
Section titled “eraseAllTargets()”Clear all previously defined targets (marginal and joint targets).
As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
- Return type:
None
eraseEvidence(*args)
Section titled “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
eraseTarget(*args)
Section titled “eraseTarget(*args)”Remove, if existing, the marginal target.
- Parameters:
- target (int) – a node Id
- nodeName (int) – a node name
- Raises:
- pyagrum.IndexError – If one of the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
- Return type:
None
evidenceImpact(*args)
Section titled “evidenceImpact(*args)”Create a pyagrum.Tensor for P(target|evs) (for all instanciation of target and evs)
- Parameters:
- target (set) – a set of targets ids or names.
- evs (set) – a set of nodes ids or names.
Warning
if some evs are d-separated, they are not included in the Tensor.
- Returns: a Tensor for P(targets|evs)
- Return type: pyagrum.Tensor
hardEvidenceNodes()
Section titled “hardEvidenceNodes()”- Returns: the set of nodes with hard evidence
- Return type: set
hasEvidence(*args)
Section titled “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)
Section titled “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
hasSoftEvidence(*args)
Section titled “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
history()
Section titled “history()”- Returns: the scheme history
- Return type: tuple
- Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
isTarget(*args)
Section titled “isTarget(*args)”- Parameters:
- variable (int) – a node Id
- nodeName (str) – a node name
- Returns: True if variable is a (marginal) target
- Return type: bool
- Raises:
- pyagrum.IndexError – If the node does not belong to the Bayesian network
- pyagrum.UndefinedElement – If node Id is not in the Bayesian network
makeInference()
Section titled “makeInference()”Perform the heavy computations needed to compute the targets’ posteriors
In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT. This is precisely what makeInference should compute. Later, the computations of the posteriors can be done ‘lightly’ by multiplying and projecting those messages.
- Return type:
None
makeInference_()
Section titled “makeInference_()”- Return type:
None
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type: int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type: float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type: str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type: float
nbrEvidence()
Section titled “nbrEvidence()”- Returns: the number of evidence entered into the Bayesian network
- Return type: int
nbrHardEvidence()
Section titled “nbrHardEvidence()”- Returns: the number of hard evidence entered into the Bayesian network
- Return type: int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type: int
nbrSoftEvidence()
Section titled “nbrSoftEvidence()”- Returns: the number of soft evidence entered into the Bayesian network
- Return type: int
nbrTargets()
Section titled “nbrTargets()”- Returns: the number of marginal targets
- Return type: int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type: int
- Raises: pyagrum.OutOfBounds – If p<1
posterior(*args)
Section titled “posterior(*args)”Computes and returns the posterior of a node.
- 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
- Raises: pyagrum.UndefinedElement – If an element of nodes is not in targets
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters: eps (float) – the epsilon we want to use
- Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setEvidence(evidces)
Section titled “setEvidence(evidces)”Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises: pyagrum.InvalidArgument – If one value is not a value for the node pyagrum.InvalidArgument If the size of a value is different from the domain side of the node pyagrum.FatalError If one value is a vector of 0s pyagrum.UndefinedElement If one node does not belong to the Bayesian network
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters: max (int) – the maximum number of iteration
- Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters: rate (float) – the minimal epsilon rate
- Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters: p (int) – number of samples between 2 stopping
- Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setTargets(targets)
Section titled “setTargets(targets)”Remove all the targets and add the ones in parameter.
- Parameters: targets (set) – a set of targets
- Raises: pyagrum.UndefinedElement – If one target is not in the Bayes net
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters: v (bool) – verbosity
- Return type:
None
setVirtualLBPSize(vlbpsize)
Section titled “setVirtualLBPSize(vlbpsize)”- Parameters: vlbpsize (float) – the size of the virtual LBP
- Return type:
None
softEvidenceNodes()
Section titled “softEvidenceNodes()”- Returns: the set of nodes with soft evidence
- Return type: set
targets()
Section titled “targets()”- Returns: the list of marginal targets
- Return type: list
property thisown
Section titled “property thisown”The membership flag
updateEvidence(evidces)
Section titled “updateEvidence(evidces)”Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
- Parameters: evidces (Dict [**str ,**Union [**int ,**str ,**List [**float ] ] ] or List [pyagrum.Tensor ]) – a dict of “name:evidence” where name is a string (the name of the variable) and evidence is an integer (an index) or a string (a label) or a list of float (a likelihood).
- Raises:
- pyagrum.InvalidArgument – If one value is not a value for the node
- pyagrum.InvalidArgument – If the size of a value is different from the domain side of the node
- pyagrum.FatalError – If one value is a vector of 0s
- pyagrum.UndefinedElement – If one node does not belong to the Bayesian network
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type: bool