Learn R Programming

bnlearn (version 4.9.4)

KL: Compute the distance between two fitted Bayesian networks

Description

Compute the Kullback-Leibler divergence between two fitted Bayesian networks.

Usage

KL(P, Q)

Value

KL() returns a numeric value.

Arguments

P, Q

two objects of class bn.fit.

Author

Marco Scutari

Examples

Run this code
if (FALSE) {
# discrete networks
dag = model2network("[A][C][F][B|A][D|A:C][E|B:F]")
fitted1 = bn.fit(dag, learning.test, method = "mle")
fitted2 = bn.fit(dag, learning.test, method = "bayes", iss = 20)

KL(fitted1, fitted1)
KL(fitted2, fitted2)
KL(fitted1, fitted2)
}

# continuous, singular networks.
dag = model2network("[A][B][E][G][C|A:B][D|B][F|A:D:E:G]")
singular = fitted1 = bn.fit(dag, gaussian.test)
singular$A = list(coef = coef(fitted1[["A"]]) + runif(1), sd = 0)

KL(singular, fitted1)
KL(fitted1, singular)

Run the code above in your browser using DataLab