LoopyWeightedSampling.addEvidence
- LoopyWeightedSampling.addEvidence(*args)
Adds a new evidence on a node (might be soft or hard).
The sampling inferences (Gibbs, Monte Carlo, Weighted, Importance and their loopy versions) accept only hard evidence.
- Parameters:
id (
int) – a node IdnodeName (
str) – a node nameval – (int) a node value
val – (str) the label of the node value
vals (
list[float]) – 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.InvalidArgument – If a value of vals is negative or not finite, or if vals is a vector of 0s (the evidence is not added)
pyagrum.FatalError – If the evidence is soft and the inference is a sampling one (the evidence is not added)
pyagrum.UndefinedElement – If the node does not belong to the Bayesian network
- Return type:
None
Example
import pyagrum as gum
bn = gum.fastBN("A->B<-C", uniform=True)
ie = gum.LoopyWeightedSampling(bn)
ie.addEvidence("A", 1) # by index
ie.addEvidence("C", "0") # by label
sorted(ie.hardEvidenceNodes())
# [0, 2]
ie.makeInference()
ie.posterior("A").tolist()
# [0.0, 1.0]
Class