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 with bn.cpt(node).fillWith(...)) is not detected.

Returns:

the values of the last computation: klPQ, errorPQ, klQP, errorQP, hellinger, bhattacharya and jensen-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

ExactBNdistance