Learn R Programming

bnlearn (version 4.1.1)

compare: Compare two different Bayesian networks

Description

Compare two different Bayesian networks; compute their Structural Hamming Distance (SHD) or the Hamming distance between their skeletons.

Usage

compare(target, current, arcs = FALSE)
# S3 method for bn
all.equal(target, current, ...)

shd(learned, true, wlbl = FALSE, debug = FALSE) hamming(learned, true, debug = FALSE)

Arguments

target, learned

an object of class bn.

current, true

another object of class bn.

extra arguments from the generic method (currently ignored).

wlbl

a boolean value. If TRUE arcs whose directions have been fixed by a whitelist or a by blacklist are preserved when constructing the CPDAGs of learned and true.

debug

a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

arcs

a boolean value. See below.

Value

compare returns a list containing the number of true positives (tp, the number of arcs in current also present in target), of false positives (fp, the number of arcs in current not present in target) and of false negatives (fn, the number of arcs not in current but present in target) if arcs is FALSE; or the corresponding arc sets if arcs is TRUE.

all.equal returns either TRUE or a character string describing the differences between target and current.

shd and hamming return a non-negative integer number.

References

Tsamardinos I, Brown LE, Aliferis CF (2006). "The Max-Min Hill-Climbing Bayesian Network Structure Learning Algorithm". Machine Learning, 65(1), 31-78.

Examples

Run this code
data(learning.test)

e1 = model2network("[A][B][C|A:B][D|B][E|C][F|A:E]")
e2 = model2network("[A][B][C|A:B][D|B][E|C:F][F|A]")
shd(e2, e1, debug = TRUE)
unlist(compare(e1,e2))
compare(target = e1, current = e2, arcs = TRUE)

Run the code above in your browser using DataLab