network tools {bnlearn}R Documentation

Utilities to manipulate graphs

Description

Assign or extract various quantities of interest from an object of class bn.

Usage


  mb(x, node, rebuild = FALSE)
  nbr(x, node, rebuild = FALSE)
  arcs(x)
  arcs(x, debug = FALSE) <- value
  nodes(x)
  amat(x)
  amat(x, debug = FALSE) <- value
  parents(x, node, rebuild = FALSE)
  parents(x, node, debug = FALSE) <- value
  children(x, node, rebuild = FALSE)
  children(x, node, debug = FALSE) <- value
  nparams(x, data, debug = FALSE)

Arguments

x an object of class "bn".
node a character string, the label of a node.
value either an array of character strings (for parents and children), an adjacency matrix (for amat) or a data frame with two columns (optionally labeled "from" and "to", for arcs)
data a data frame, containing the data the Bayesian network was learned from.
rebuild a boolean value. If TRUE the return value is rebuilt from scratch using the arc list; otherwise the cached value are returned.
debug a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Details

The number of parameters of a discrete Bayesian network is computed as the sum of the number of logically independent parameters of each node given its parents (Chickering, 1995).

Value

mb, nbr, nodes and parents return an array of character strings. arcs returns a matrix of two columns of character strings. amat returns a matrix of 0/1 numeric values. nparams returns an integer.

Note

nparams supports only completely directed discrete Bayesian networks.

Author(s)

Marco Scutari

References

D. M. Chickering. A Transformational Characterization of Equivalent Bayesian Network Structures. In Proceedins of 11th Conference on Uncertainty in Artificial Intelligence, pages 87-98. Morgan Kaufmann Publishers Inc., 1995.

Examples


data(learning.test)
res = gs(learning.test)

# the Markov blanket of A.
mb(res, "A")
# [1] "B" "D" "C"
# the neighbourhood of F.
nbr(res, "F")
# [1] "E"
# the arcs in the graph.
arcs(res)
#      from to
# [1,] "A"  "B"
# [2,] "A"  "D"
# [3,] "B"  "A"
# [4,] "B"  "E"
# [5,] "C"  "D"
# [6,] "F"  "E"
# the nodes of the graph.
nodes(res)
# [1] "A" "B" "C" "D" "E" "F"
# the adjacency matrix for the nodes of the graph.
amat(res)
#   A B C D E F
# A 0 1 0 1 0 0
# B 1 0 0 0 1 0
# C 0 0 0 1 0 0
# D 0 0 0 0 0 0
# E 0 0 0 0 0 0
# F 0 0 0 0 1 0
# the parents of D.
parents(res, "D")
# [1] "A" "C"
children(res, "A")
# [1] "D"
# number of parameters of the baysesian network.
res = set.arc(res, "A", "B")
nparams(res, learning.test)
# [1] 41


[Package bnlearn version 0.4 Index]