ImportanceSampling.posterior
- ImportanceSampling.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 probabilitynodeName (
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:
- Raises:
pyagrum.UndefinedElement – If an element of nodes is not in targets
Example
import pyagrum as gum
bn = gum.fastBN("A->B")
bn.cpt("A").fillWith([0.2, 0.8])
bn.cpt("B")[:] = [[0.9, 0.1], [0.3, 0.7]]
gum.initRandom(42)
ie = gum.ImportanceSampling(bn)
ie.setEpsilon(1e-2)
ie.addEvidence("B", 1)
ie.makeInference()
ie.posterior("A").names
# ('A',)
abs(ie.posterior("A")[0] - 0.0345) < 0.05 # sampling: close to the exact 0.0345
# True
Class
Overridden in