Learn R Programming

bnlearn (version 1.6)

graph generation tools: Generate an empty or random graph

Description

Generate an empty or random graph from a given set of nodes.

Usage

empty.graph(nodes, num = 1)
  random.graph(nodes, num = 1, method = "ordered", ..., debug = FALSE)

Arguments

nodes
a vector of character strings, the labels of the nodes.
num
an integer, the number of graphs to be generated.
method
a character string, the label of a score. Possible values are ordered (full ordering based generation), ic-dag (Ide's and Cozman's Generating Multi-connected DAGs algorithm) and empty
...
additional tuning parameters (see below).
debug
a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent. Ignored in some generation methods.

Value

  • Both empty.graph and random.graph return an object of class bn (if num is equal to 1) or a list of objects of class bn (otherwise).

Details

Available graph generation algorithms are:

  • full orderingbased generation (ordered): generates graphs whose node ordering is given by the order of the labels in thenodesparameter. The same algorithm is used in therandomDAGfunction in packagepcalg.
  • Ide's and Cozman'sGenerating Multi-connected DAGsalgorithm (ic-dag): generates graphs with a uniform probability distribution over the set of multiconnected graphs.
  • empty graphs(empty): generates graphs without any arc.

Additional parameters for the random.graph function are:

  • prob: the probability of each arc to be present in a graph generated by theorderedalgorithm. The default value is2 / (length(nodes) - 1), which results in a sparse graph (the number of arcs should be of the same order as the number of nodes).
  • burn.in: the number of iterations for theic-dagalgorithm to converge to a stationary (and uniform) probability distribution. The default value is6 * length(nodes)^2.
  • max.degree: the maximum degree for any node in a graph generated by theic-dagalgorithm. The default value isInf.
  • max.in.degree: the maximum in-degree for any node in a graph generated by theic-dagalgorithm. The default value isInf.
  • max.out.degree: the maximum out-degree for any node in a graph generated by theic-dagalgorithm. The default value isInf.

References

Ide JS, Cozman FG (2002). "Random Generation of Bayesian Networks". In "SBIA '02: Proceedings of the 16th Brazilian Symposium on Artificial Intelligence", pp. 366-375. Springer-Verlag.

Examples

Run this code
empty.graph(LETTERS[1:8])
#
#  Randomly generated Bayesian network
#
#  model:
#    [A][B][C][D][E][F][G][H]
#  nodes:                                 8
#  arcs:                                  0
#    undirected arcs:                     0
#    directed arcs:                       0
#  average markov blanket size:           0.00
#  average neighbourhood size:            0.00
#  average branching factor:              0.00
#
#  generation algorithm:                  empty
#
random.graph(LETTERS[1:8])
# <insert the description of a random graph here>
plot(random.graph(LETTERS[1:8], method = "ic-dag", max.in.degree = 2))
plot(random.graph(LETTERS[1:8]))
plot(random.graph(LETTERS[1:8], prob = 0.2))

Run the code above in your browser using DataLab