KTBNInference.posterior
- KTBNInference.posterior(*args)
Return P(base[slice] | obs, do(…)). Lazily (re)runs
makeInference()with the last horizon if the cache is out of date. The returned reference is owned by the engine and invalidated by the nextmakeInference()call: copy it to keep it.- Parameters:
base (
str) – base name of the queried node (used together with slice)slice (
int) – slice of the queried node (pyagrum.ktbn.KTBN.ATEMPORALfor a static node)node_name (
str) – alternatively, the node’s engine name
- Returns:
the posterior distribution
- Return type:
- Raises:
pyagrum.OperationNotAllowed – if makeInference has never been run
pyagrum.UndefinedElement – if base is not a target
pyagrum.OutOfBounds – if slice was not computed (>= the horizon)
Example
import pyagrum as gum
import pyagrum.ktbn as ktbn
model = ktbn.KTBN.fromBN(gum.fastBN("X0->X1"))
model.cpt("X", 0).fillWith([0.5, 0.5])
model.cpt("X", 1).fillWith([0.9, 0.1, 0.2, 0.8]) # P(X[t] | X[t-1])
ie = ktbn.KTBNInference(model)
ie.makeInference(3)
print(ie.posterior("X", 2))
#
# X[2] │
# 0 │1 │
# ─────────│─────────│
# 0.5850 │ 0.4150 │
print(ie.posterior("X[1]"))
#
# X[1] │
# 0 │1 │
# ─────────│─────────│
# 0.5500 │ 0.4500 │
Class