Learn R Programming

bnlearn (version 1.6)

network tools: Utilities to manipulate graphs

Description

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

Usage

## nodes
  nodes(x)
  mb(x, node, rebuild = FALSE)
  nbr(x, node, rebuild = FALSE)
  parents(x, node, rebuild = FALSE)
  parents(x, node, debug = FALSE) <- value
  children(x, node, rebuild = FALSE)
  children(x, node, debug = FALSE) <- value
  root.nodes(x)
  leaf.nodes(x)

## arcs arcs(x) arcs(x, ignore.cycles = FALSE, debug = FALSE) <- value directed.arcs(x) undirected.arcs(x)

## adjacency matrix amat(x) amat(x, ignore.cycles = FALSE, debug = FALSE) <- value

## graphs nparams(x, data, debug = FALSE) acyclic(x, directed, debug = FALSE) directed(x) path(x, from, to, direct = TRUE, underlying.graph = FALSE, debug = FALSE)

Arguments

x
an object of class bn.
node
a character string, the label of a node.
from
a character string, the label of a node.
to
a character string, the label of a node (different from from).
value
either a vector 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 set; otherwise the cached value are returned.
direct
a boolean value. If FALSE ignore any arc between from and to when looking for a path.
directed
a boolean value. If TRUE the graph is assumed to be completely directed (no undirected arcs), and a faster cycle detection algorithm is used.
underlying.graph
a boolean value. If TRUE the underlying undirected graph is used instead of the (directed) one from the x parameter.
ignore.cycles
a boolean value. If TRUE the returned network will not be checked for cycles.
debug
a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Value

  • mb, nbr, nodes, parents, rootnodes and leafnodes return a vector 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. acyclic, path and directed return a boolean value.

Details

The number of parameters of a discrete Bayesian network is defined as the sum of the number of logically independent parameters of each node given its parents (Chickering, 1995). For Gaussian Bayesian networks the distribution of each node can be viewed as a linear regression, so it has a number of parameters equal to the number of the parents of the node plus one (the intercept) as per Neapolitan (2003).

References

Chickering DM (1995). "A Transformational Characterization of Equivalent Bayesian Network Structures". In "UAI '95: Proceedings of the Eleventh Annual Conference on Uncertainty in Artificial Intelligence", pp. 87-98. Morgan Kaufmann.

Neapolitan RE (2003). Learning Bayesian Networks. Prentice Hall.

Examples

Run this code
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"
## the children of A.
children(res, "A")
# [1] "D"
## the root nodes of the graph.
root.nodes(res)
# [1] "C" "F"
## the leaf nodes of the graph.
leaf.nodes(res)
# [1] "D" "E"
## number of parameters of the Bayesian network.
res = set.arc(res, "A", "B")
nparams(res, learning.test)
# [1] 41

Run the code above in your browser using DataLab