Learn R Programming

bnlearn (version 3.1)

compare: Compare two different Bayesian networks

Description

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

Usage

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

shd(learned, true, 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).
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 (tn, 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)
# * arcs between A and F do not match.
#   > the learned network contains A - F.
#   > the true network contains A -> F.
# * arcs between E and F do not match.
#   > the learned network contains F -> E.
#   > the true network contains E -> F.
# [1] 2
unlist(compare(e1,e2))
# tp fp fn
#  5  1  1
compare(target = e1, current = e2, arcs = TRUE)
# $tp
#      from to
# [1,] "A"  "C"
# [2,] "B"  "C"
# [3,] "B"  "D"
# [4,] "C"  "E"
# [5,] "A"  "F"
#
# $fp
#      from to
# [1,] "F"  "E"
#
# $fn
#      from to
# [1,] "E"  "F"

Run the code above in your browser using DataLab