Skip to contents

Posterior P(query given evidence) by sum-product variable elimination: every conditional probability table becomes a factor, evidence rows are selected out, each hidden non-query variable is summed out of the product of the factors that mention it, and the surviving factors are multiplied and normalized. The elimination order is lexicographic over the hidden variables – deterministic, identical to the Python arm, and the order affects only cost, never the result.

Usage

Baynet(graph, cpts, evidence = list(), query = NULL)

bayes_network(graph, cpts, evidence = list(), query = NULL)

Arguments

graph

Named list: node -> character vector of parent names (ordered as in the CPT axes).

cpts

Named list: node -> nested list or array with axes (parent_1, ..., parent_k, node).

evidence

Named list: node -> observed state index (0-based, matching the Python arm).

query

The query node name.

Value

List with posterior, states, estimate (0-based argmax), normalizer, query.

References

Zhang, N. L. and Poole, D. (1994). A simple approach to Bayesian network computations. Proc. 10th Canadian Conference on AI, 171-178.

Pearl, J. (1988). Probabilistic Reasoning in Intelligent Systems. Morgan Kaufmann.

Koller, D. and Friedman, N. (2009). Probabilistic Graphical Models. MIT Press, Ch. 9.

Examples

graph <- list(C = character(0), R = "C")
cpts <- list(C = c(0.5, 0.5), R = list(c(0.8, 0.2), c(0.2, 0.8)))
Baynet(graph, cpts, list(), "R")
#> $posterior
#> [1] 0.5 0.5
#> 
#> $states
#> [1] 2
#> 
#> $estimate
#> [1] 0
#> 
#> $normalizer
#> [1] 1
#> 
#> $query
#> [1] "R"
#> 
#> $method
#> [1] "Variable elimination (Zhang-Poole 1994), lexicographic order"
#>