Index | Topics |
compare {bnlearn} | R Documentation |
Compare two or more different Bayesian networks
Description
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,
Usage
compare(target, current, arcs = FALSE)
## S3 method for class 'bn'
all.equal(target, current, ...)
sid(learned, true, debug = FALSE)
shd(learned, true, wlbl = FALSE, cpdag = TRUE, debug = FALSE)
hamming(learned, true, debug = FALSE)
graphviz.compare(x, ..., groups, layout = "dot", shape = "rectangle",
fontsize = 12, main = NULL, sub = NULL, diff = "from-first",
diff.args = list())
Arguments
target , learned |
an object of class |
current , true |
another object of class |
... |
extra arguments from the generic method (for |
wlbl |
a boolean value. If |
cpdag |
a boolean value. If |
debug |
a boolean value. If |
arcs |
a boolean value. See below. |
x |
an object of class |
groups |
a list of character vectors, representing groups of node labels of nodes that should be plotted close to each other. |
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 |
fontsize |
a positive number, the font size for the node labels. |
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
|
Details
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 firstbn
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 thediff.args
argument, with namestp.col
,tp.lty
,tp.lwd
,fp.col
,fp.lty
,fp.lwd
,fn.col
,fn.lty
,tp.lwd
. In addition, it is possible not to plot the reference network at all by settingshow.first
toFALSE
.
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.
shd()
computes the Structural Hamming Distance (SHD). 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.
sid()
computes the Structural Interventional Distance (SID) between two DAGs, between a
CPDAG and a DAG, and between a DAG and a CPDAG.
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.
sid()
returns a non-negative integer number, with additional attributes describing the
distribution over all the evaluated graphs.
graphviz.compare()
plots one or more figures and returns invisibly a list containing the
graph
objects generated from the networks that were passed as arguments (in the same order).
They can be further modified using the graph and Rgraphviz packages. Unlike the other functions, graphviz.compare()
accepts
networks with different node sets as long as they overlap.
Author(s)
Marco Scutari
References
Tsamardinos I, Brown LE, Aliferis CF (2006). "The Max-Min Hill-Climbing Bayesian Network Structure Learning Algorithm." Machine Learning, 65(1):31–78.
Peters J, Buhlmann P (2015). "Structural Intervention Distance for Evaluating Causal Graphs." Neural Computation, 27(3):771–779.
Examples
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)
sid(e2, e1, debug = TRUE)
unlist(compare(e1,e2))
compare(target = e1, current = e2, arcs = TRUE)
## Not run: graphviz.compare(e1, e2, diff = "none")
Index | Topics |