queryNet: Query the Bayesian network

Description Usage Arguments Value Examples

View source: R/queryNet.R

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

1
2
3
queryNet(network, target, evidence, ...)

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

Arguments

network

The Bayesian network. An object of class grain (from package bnlearn), 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 or data.frame. Named columns are the known input variables; 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data(ConwyData)
list2env(ConwyData, environment())

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
q <- queryNetParallel(network, 'FinalLULC', evidence, inparallel=2)
head(q)

bnspatial documentation built on Nov. 18, 2017, 4:13 a.m.