Learn R Programming

bnspatial (version 0.9)

queryNet: Query the Bayesian network

Description

This function queries the Bayesian network and returns the probabilities for each state of the target node. Available input variables are set as evidence. queryNetParallel works as queryNet, but makes use of multi cores/processors facilities for big network queries, by splitting data into chunks and processing them in parallel.

Usage

queryNet(network, target, evidence, ...)
queryNetParallel(network, target, evidence, inparallel = TRUE, ...)

Arguments

network
The Bayesian network. An object of class "grain" (package gRain), or a character (the path to the ".net" file to be imported)
target
character. The node of interest to be modelled and mapped.
evidence
matrix. Named columns are the known input variables; in rows are the discrete states associated to them for each record (NA allowed).
...
Additional arguments to fix a state (i.e. setting evidence) to one or more nodes, as known and independent from any spatial data (e.g. the case of non-spatial variables which are equal everywhere). Node name is provided as argument and the associated fixed state as character; both node and state names must be typed accordingly to their names in the network.
inparallel
logical or integer. Number of cores/processors to be used by queryNetParallel. Default is TRUE, so the maximum number available minus one is set.

Value

A matrix of probabilities: columns are the target node states and rows are the probabilities associated to each record from argument evidence (e.g. spatial locations).

Examples

Run this code
data(ConwyData)
network <- LandUseChange

q <- queryNet(network, 'FinalLULC', evidence)
head(q)

## Fix a given node on a state (i.e. fixed evidence) by providing an additional argument
q <- queryNet(network, 'FinalLULC', evidence, Stakeholders = 'farmers')
head(q)

## Use parallel processing
library(doParallel)
q <- queryNetParallel(network, 'FinalLULC', evidence, inparallel=2)
head(q)

Run the code above in your browser using DataLab