Propagation refers to calibrating the cliques of the junction tree so that the clique potentials are consistent on their intersections; refer to the reference below for details.

# S3 method for class 'grain'
propagate(object, details = object$details, engine = "cpp", ...)

propagateLS(cq_pot_list, rip, initialize = TRUE, details = 0)

Arguments

object

A grain object

details

For debugging info

engine

Either "R" or "cpp"; "cpp" is the default and the fastest.

...

Currently not used

cq_pot_list

List of clique potentials

rip

A rip ordering

initialize

Always true.

Value

A compiled and propagated grain object.

Details

The propagate method invokes propagateLS which is a pure R implementation of the Lauritzen-Spiegelhalter algorithm. The c++ based version is several times faster than the purely R based version.

References

Søren Højsgaard (2012). Graphical Independence Networks with the gRain Package for R. Journal of Statistical Software, 46(10), 1-26. https://www.jstatsoft.org/v46/i10/.

See also

Author

Søren Højsgaard, sorenh@math.aau.dk

Examples


example("grain")
#> 
#> grain> ## Create network from conditional probability tables CPTs:
#> grain> 
#> grain> yn   <- c("yes", "no")
#> 
#> grain> a    <- cpt(~asia,                  values=c(1,99), levels=yn)
#> 
#> grain> t.a  <- cpt(~tub + asia,            values=c(5,95,1,99), levels=yn)
#> 
#> grain> s    <- cpt(~smoke,                 values=c(5,5), levels=yn)
#> 
#> grain> l.s  <- cpt(~lung + smoke,          values=c(1,9,1,99), levels=yn)
#> 
#> grain> b.s  <- cpt(~bronc + smoke,         values=c(6,4,3,7), levels=yn)
#> 
#> grain> e.lt <- cpt(~either + lung + tub,   values=c(1,0,1,0,1,0,0,1), levels=yn)
#> 
#> grain> x.e  <- cpt(~xray + either,         values=c(98,2,5,95), levels=yn)
#> 
#> grain> d.be <- cpt(~dysp + bronc + either, values=c(9,1,7,3,8,2,1,9), levels=yn)
#> 
#> grain> cpt_list  <- list(a, t.a, s, l.s, b.s, e.lt, x.e, d.be)
#> 
#> grain> chest_cpt <- compileCPT(cpt_list)
#> 
#> grain> ## Alternative: chest_cpt <- compileCPT(a, t.a, s, l.s, b.s, e.lt, x.e, d.be)
#> grain> 
#> grain> chest_bn  <- grain(chest_cpt)
#> 
#> grain> ## Create network from data and graph specification.
#> grain> 
#> grain> data(lizard, package="gRbase")
#> 
#> grain> ## From a DAG: height <- species -> diam
#> grain> daG <- dag(~species + height:species + diam:species, result="igraph")
#> 
#> grain> ## From an undirected graph UG : [height:species][diam:species]
#> grain> uG  <- ug(~height:species + diam:species, result="igraph")
#> 
#> grain> liz.ug   <- grain(uG, data=lizard)
#> 
#> grain> liz.dag  <- grain(daG, data=lizard)

## Uncompiled and unpropageted network:
bn0  <- grain(chest_cpt, compile=FALSE)
bn0
#> Independence network: Compiled: FALSE Propagated: FALSE Evidence: FALSE 
## Compiled but unpropageted network:
bn1  <- compile(bn0, propagate=FALSE)
## Compiled and propagated network
bn2  <- propagate(bn1)
bn2
#> Independence network: Compiled: TRUE Propagated: TRUE Evidence: FALSE 
## Default is that networks are compiled but not propagated at creation time:
bn3  <- grain(chest_cpt) 
bn3 
#> Independence network: Compiled: TRUE Propagated: FALSE Evidence: FALSE