| compare {bnlearn} | R Documentation |
Compare two different Bayesian networks; compute their Structural Hamming Distance (SHD) or the Hamming distance between their skeletons. Or graphically compare them by plotting them side by side,
compare(target, current, arcs = FALSE) ## S3 method for class 'bn' all.equal(target, current, ...) shd(learned, true, wlbl = FALSE, debug = FALSE) hamming(learned, true, debug = FALSE) graphviz.compare(x, ..., layout = "dot", shape = "circle", main = NULL, sub = NULL, diff = "from-first", diff.args = list())
target, learned |
an object of class |
current, true |
another object of class |
... |
extra arguments from the generic method (for |
wlbl |
a boolean value. If |
debug |
a boolean value. If |
arcs |
a boolean value. See below. |
x |
an object of class |
layout |
a character string, the layout argument that will be passed to
Rgraphviz. Possible values are |
shape |
a character string, the shape of the nodes. Can be |
main |
a vector of character strings, one for each network. They are plotted at the top of the corresponding figure(s). |
sub |
a vector of character strings, the subtitles that are plotted at the bottom of the corresponding figure(s). |
diff |
a character string, the label of the method used to compare and
format the figure(s) created by |
diff.args |
a list of optional arguments to control the formatting of
the figure(s) created by |
graphviz.compare() can visualize differences between graphs in various
way depending on the value of the diff and diff.args arguments:
none: differences are not highlighted.
from-first: the first bn object, x, is taken as
the reference network. All the other networks, passed via the ...
argument, are compared to that first network and their true positive,
false positive, false negative arcs relative to that first network are
highlighted. Colours, line types and line widths for each category of
arcs can be specified as the elements of a list via the diff.args
argument, with names tp.col, tp.lty, tp.lwd,
fp.col, fp.lty, fp.lwd, fn.col, fn.lty,
tp.lwd.
Regardless of the visualization, the nodes are arranged to be in the same position for all the networks to make it easier to compare them.
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.
graphviz.compare() plots one or more figures and returns NULL
invisibly.
Note that SHD, as defined in the reference, is defined on CPDAGs; therefore
cpdag() is called on both learned and true before computing
the distance.
Marco Scutari
Tsamardinos I, Brown LE, Aliferis CF (2006). "The Max-Min Hill-Climbing Bayesian Network Structure Learning Algorithm". Machine Learning, 65(1), 31-78.
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)
graphviz.compare(e1, e2, diff = "none")