Learn R Programming

bnlearn (version 0.3)

bnlearn-package: Bayesian network constraint-based structure learning.

Description

Bayesian network learning via constraint-based algorithms.

Arguments

Available learning algorithms

  • Grow-Shrink(gs): based on theGrow-Shrink Markov Blanketalgorithm, a forward-selection technique for Markov blanket detection.
  • Incremental Association(iamb): based on the Markov blanket detection algorithm of the same name, which uses stepwise selection.
  • Fast Incremental Association(fast.iamb): a variant of IAMB which uses speculative forward-selection to reduce the number of conditional independence tests.
  • Interleaved Incremental Association(inter.iamb): another variant of IAMB which interleaves the backward selection with the forward one to avid false positives (i.e. nodes erroneously included in the Markov blanket).

This package includes three implementations of each algorithm:

  • an optimized implementation, which uses backtracking to roughly halve the number of independence tests. This is the one used by default, when theoptimizedparameter is set to {TRUE}.
  • an unoptimized implementation which is better at uncovering possible erratic behaviour of the statistical tests. To use this one theoptimizedparameter must be set to {FALSE}.
  • a cluster-aware implementation, which requires a running cluster set up with themakeClusterfunction from thesnowpackage. To use this on pass the cluster object to the various functions via theclusterparameter; theoptimizedparameter will be ignored.

Their computational complexity is polynomial in the number of tests, usually $O(N^2)$ ($O(N^4)$ in the worst case scenario). The execution time also scales linearly with the size of the data set.

Available (conditional) independence tests

The conditional independence tests used in constraint-based algorithms in practice are statistical tests on the data set. Available tests (and the respective labels) are:

  • categorical data(multinomial distribution)
    • mutual information(mi): an information-theoretic distance measure. Is proportional to the log-likelihood ratio (they differ by a$2n$factor) and is related to the deviance of the tested models.
    • fast mutual information(fmi): a variant of the mutual information which is set to zero when there aren't at least five data per parameter.
    • Cochran-Mantel-Haenszel(mh): a stratified independence test, included for testing purposes only. Seemantelhaen.testin packagestats.
  • numerical data(multivariate normal distribution)
    • linear correlation(cor): linear correlation.
    • Fisher's Z(zf): a transformation of the linear correlation with asymptotic normal distribution. Used by commercial software (such as TETRAD II) for the PC algorithm (an R implementation is present in thepcalg) package on CRAN.

Whitelist and blacklist support

All algorithms support arc whitelisting and blacklisting:

  • blacklisted arcs are never present in the graph.
  • arcs whitelisted in one direction only (i.e.$A \rightarrow B$is whitelisted but$B \rightarrow A$is not) have the respective reverse arcs blacklisted, and are always present in the graph.
  • arcs whitelisted in both directions (i.e. both$A \rightarrow B$and$B \rightarrow A$are whitelisted) are present in the graph, but their direction is set by the learning algorithm.

Any arc whitelisted and blacklisted at the same time is assumed to be whitelisted, and is thus removed from the blacklist.

Error detection and correction: the strict mode

Optimized implementations of learning algorithms often hide learning errors, usually in the Markov blanket detection step, due to the use of backtracking.

On the other hand in the unoptimized implementations the Markov blanket and neighbour detection of each node is completely independent from the rest of the learning process. Thus it may happen that the Markov blanket or the neighbourhoods are not symmetric (i.e. A is in the Markov blanket but not vice versa), or that some arc directions conflict with each other.

The strict parameter enables some measure of error correction, which may help to retrieve a good model even when the learning process would fail:

itemize if strict is set to TRUE, every error stops the learning process and results in an error message. if strict is set to FALSE: enumerate v-structures are applied to the network structure in lowest-p.value order; if any arc is already oriented in the opposite direction, the v-structure is discarded. nodes which causes asymmetries in any Markov blanket are removed from that Markov blanket. nodes which causes asymmetries in any neighbourhood are removed from that neighbourhood. enumerate itemize

The bn S3 class
{

An object of class bn is a list containing at least the following components:

  • nodes: a list. Each element is named after a node and contains the following elements:
    • mb: the Markov blanket blanket of the node (an array of character strings).
    • nbr: the neighbourhood of the node (an array of character strings).
  • arcs: the arcs of the Bayesian network (a two-column matrix, whose column are labeledfromandto)
  • whitelist: a sanitized copy of thewhitelistparameter (a two-column matrix, whose column are labeledfromandto).
  • blacklist: a sanitized copy of theblacklistparameter (a two-column matrix, whose column are labeledfromandto).
  • test: the label of the conditional independence test used by the learning algorithm (a character string).
  • alpha: the target nominal type I error rate (a numerical value).
  • ntests: the number of conditional independence tests used in the learning (an integer value).
  • algo: the label of the learning algorithm used (a character string).
  • discrete: is the network a discrete (multinomial) one (a boolean value)?

} A. Agresti. Categorical Data Analysis. John Wiley & Sons, Inc., 2002. D. Margaritis. Learning Bayesian Network Model Structure from Data. PhD thesis, School of Computer Science, Carnegie-Mellon University, Pittsburgh, PA, May 2003. Available as Technical Report CMU-CS-03-153.

J. Pearl. Probabilistic Reasoning in Intelligent Systems: Networks of Plausible Inference. Morgan Kaufmann Publishers Inc., 1988.

I. Tsamardinos, C. F. Aliferis, and A. Statnikov. Algorithms for large scale markov blanket discovery. In Proceedings of the Sixteenth International Florida Artificial Intelligence Research Society Conference, pages 376-381. AAAI Press, 2003.

S. Yaramakala, D. Margaritis. Speculative Markov Blanket Discovery for Optimal Feature Selection. In Proceedings of the Fifth IEEE International Conference on Data Mining, pages 809-812. IEEE Computer Society, 2005. library(bnlearn) data(learning.test)

## Simple learning # first try the Grow-Shrink algorithm res = gs(learning.test) # plot the network structure. plot(res) # now try the Incremental Association algorithm. res2 = iamb(learning.test) # plot the new network structure. plot(res2) # the network structures seem to be identical, don't they? compare(res, res2) # [1] TRUE # how many tests each of the two algorithms used? res$ntests # [1] 44 res2$ntests # [1] 51 # and the unoptimized implementation of these algorithms? gs(learning.test, optimized = FALSE)$ntests # [1] 90 iamb(learning.test, optimized = FALSE)$ntests # [1] 124

## Blacklist and whitelist use # the arc B - F should not be there? blacklist = data.frame(from = c("B", "F"), to = c("F", "B")) blacklist # from to # 1 B F # 2 F B res3 = gs(learning.test, blacklist = blacklist) plot(res3) # force E - F direction (E -> F). whitelist = data.frame(from = c("E"), to = c("F")) whitelist # from to # 1 E F res4 = gs(learning.test, whitelist = whitelist) plot(res4) # use both blacklist and whitelist. res5 = gs(learning.test, whitelist = whitelist, blacklist = blacklist) plot(res5)

## Debugging # use the debugging mode to see the learning algorithm # in action. res = gs(learning.test, debug = TRUE) # log the learning process for future reference. sink(file = "learning-log.txt") res = gs(learning.test, debug = TRUE) sink() # if something seems wrong, try the unoptimized version # in strict mode (inconsistencies trigger errors): res = gs(learning.test, optimized = FALSE, strict = TRUE, debug = TRUE) # or disable strict mode to try to fix errors on the fly: res = gs(learning.test, optimized = FALSE, strict = FALSE, debug = TRUE) package

Details

ll{

Package: bnlearn Type: Package Version: 0.3 Date: 2007-09-15 License: GPLv2 or later

}

This package implements some constraint-based algorithms for learning the structure of Bayesian networks. Also known as conditional independence learners, they are all optimized derivatives of the Inductive Causation algorithm (Verma and Pearl, 1991).

These algorithms differ in the way they detect the Markov blankets of the variables, which in turn are used to compute the structure of the Bayesian network. Proofs of correctness are present in the respective papers.