Learn R Programming

MoTBFs (version 2.0)

get_approx_posterior: Approximate inference

Description

get_approx_posterior() returns an approximation to the posterior probability distribution of a target variable given a set of observed variables. The inference process is based on sample generation. See details.

Usage

get_approx_posterior(
  bn,
  target,
  evidence = NULL,
  size = 100,
  parallel = FALSE,
  ...
)

Value

A list of two elements: 1) the posterior probability distribution of the target variable, and 2) a data.frame with the generated sample, whose weights are attached as an attribute called weights (if evidence is not NULL).

Arguments

bn

An object of class motbf_fit, obtained from function motbf.fit.

target

A character string equal to the name of the variable of interest.

evidence

A data.frame of one row containing the value of the observed variables.

size

A non-negative integer giving the number of random samples to generate from bn.

parallel

logical indicating if the particle generation should be parallelized. As a default, it is set to FALSE.

...

Optional arguments passed on to the univMoTBF function. evalRange, nparam and maxParam can be specified. POTENTIAL_TYPE is taken from the 'bn' object.

Details

If any node is observed, i.e., argument evidence is not NULL, samples are generated from the Bayesian network using the likelihood weighting algorithm. Otherwise, i.e., no node is observed, samples are generated using the forward sampling algorithm.

References

Henrion, M. (1988). Propagating uncertainty in Bayesian networks by probabilistic logic sampling. In Machine Intelligence and Pattern Recognition (Vol. 5, pp. 149-163). North-Holland.

Examples

Run this code

## Dataset
  data("ecoli", package = "MoTBFs")
  data <- ecoli[,-c(1,9)]

## Get directed acyclic graph
  dag <- LearningHC(data)
  
## Learn bayesian network
  bn <- motbf.fit(dag, data = data, numIntervals = 4, POTENTIAL_TYPE = "MOP")
  
## Specify the evidence set and target variable
  obs <- data.frame(lip = "0.48", alm1 = 0.55, gvh = 1, stringsAsFactors=FALSE)
  node <- "alm2"
  
## Get the posterior distribution of 'node' given "evidence" and the generated sample
  get_approx_posterior(bn, target = node, evidence = obs, size = 10, maxParam = 15)
  

Run the code above in your browser using DataLab