qBNRejection.posterior

qBNRejection.posterior(node)

Return the posterior distribution of a variable as a Tensor.

Calls makeInference() if results are not yet available.

Parameters:

node (int | str) – Variable name or node ID.

Returns:

pyAgrum Tensor with the posterior probability vector.

Return type:

Tensor

Example

import pyagrum as gum
from pyagrum.qBNSampling import qBNMC, qBNRejection

bn = gum.fastBN("A->B", uniform=True)
qinf = qBNRejection(qBNMC(bn))
qinf.setEvidence({"B": 1})
qinf.setMaxIter(10)
p = qinf.posterior("A")  # runs the inference if needed
p.names
# ('A',)
round(p.sum(), 6)
# 1.0
[round(v, 4) for v in qinf.posterior("B").tolist()]
# [0.0, 1.0]

Class

qBNRejection