ExactBNdistance.computeο
- ExactBNdistance.compute(lazy=True)ο
Computes the divergences and distances between the two Bayesian networks.
- Parameters:
lazy (
bool) β if True (default), the computation is done only if the results are outdated: nothing has been computed yet, or a parameter of the approximation (stopping criteria, burn-inβ¦) changed since the last computation. If False, the computation is always done: the Bayesian networks are only referenced, so that a change made in place in one of them (for instance withbn.cpt(node).fillWith(...)) is not detected.- Returns:
the values of the last computation:
klPQ,errorPQ,klQP,errorQP,hellinger,bhattacharyaandjensen-shannon.- Return type:
dict
Example
import pyagrum as gum
p = gum.fastBN("A->B")
p.cpt("A").fillWith([0.2, 0.8])
p.cpt("B").fillWith([0.5, 0.5, 0.9, 0.1])
q = gum.BayesNet(p)
q.cpt("A").fillWith([0.5, 0.5])
res = gum.ExactBNdistance(p, q).compute()
sorted(res)
# ['bhattacharya', 'errorPQ', 'errorQP', 'hellinger', 'jensen-shannon', 'klPQ', 'klQP']
round(res["klPQ"], 4)
# 0.2781
round(res["hellinger"], 4)
# 0.3204
Class