Compiled objects are used as building blocks for junction tree inference
compile(
x,
evidence = NULL,
root_node = "",
joint_vars = NULL,
tri = "min_fill",
pmf_evidence = NULL,
alpha = NULL,
initialize_cpts = TRUE
)# S3 method for cpt_list
compile(
x,
evidence = NULL,
root_node = "",
joint_vars = NULL,
tri = "min_fill",
pmf_evidence = NULL,
alpha = NULL,
initialize_cpts = TRUE
)
An object returned from cpt_list
(baeysian network) or
pot_list
(decomposable markov random field)
A named vector. The names are the variabes and the elements are the evidence.
A node for which we require it to live in the root clique (the first clique).
A vector of variables for which we require them to be in the same clique. Edges between all these variables are added to the moralized graph.
The optimization strategy used for triangulation if x originates from a Baeysian network. One of
'min_fill'
'min_rfill'
'min_sp'
'min_ssp'
'min_lsp'
'min_lssp'
'min_elsp'
'min_elssp'
'min_nei'
'minimal'
'alpha'
A named vector of frequencies of the expected
missingness of a variable. Variables with frequencies of 1 can be
neglected; these are inferrred. A value of 0.25 means, that the
given variable is expected to be missing (it is not a evidence node)
in one fourth of the future cases. Relevant for tri
methods
'min_elsp' and 'min_elssp'.
Character vector. A permutation of the nodes in the graph. It specifies a user-supplied eliminination ordering for triangulation of the moral graph.
TRUE
if the CPTs should be initialized,
i.e. multiplied together to form the clique potentials. If FALSE,
the compile
d object will save the triangulation and other
information that needs only bee computed once. Herafter, it is
possible to enter evidence into the CPTs, using set_evidence
,
saving a lot of computations.
The Junction Tree Algorithm performs both a forward and inward
message pass (collect and distribute). However, when the forward
phase is finished, the root clique potential is guaranteed to be the
joint pmf over the variables involved in the root clique. Thus, if
it is known in advance that a specific variable is of interest, the
algortihm can be terminated after the forward phase. Use the root_node
to specify such a variable and specify propagate = "collect"
in
the juntion tree algortihm function jt
.
Moreover, if interest is in some joint pmf for variables that end up
being in different cliques these variables must be specified in advance
using the joint_vars
argument. The compilation step then
adds edges between all of these variables to ensure that at least one
clique contains all of them.
Evidence can be entered either at compile stage or after compilation. Hence, one can also combine evidence from before compilation with evidence after compilation. Before refers to entering evidence in the 'compile' function and after refers to entering evidence in the 'jt' function.
Finally, one can either use a Bayesian network or a decomposable
Markov random field (use the ess
package to fit these). Bayesian
networks must be constructed with cpt_list
and decomposable MRFs
can be constructed with both pot_list
and cpt_list
. However,
pot_list
is just an alias for cpt_list
which handles both
cases internally.
cptl <- cpt_list(asia2)
cp1 <- compile(cptl, evidence = c(bronc = "yes"), joint_vars = c("bronc", "tub"))
print(cp1)
names(cp1)
dim_names(cp1)
plot(get_graph(cp1))
Run the code above in your browser using DataLab