NodeProbs {RNetica}R Documentation

Gets or sets the conditional probability table associated with a Netica node.

Description

A complete Bayesian networks defines a conditional probability distribution for a node given its parents. If all the nodes are discrete, this comes in the form of a conditional probability table a multidimensional array whose first several dimensions follow the parent variable and whose last dimension follows the child variable.

Usage

NodeProbs(node)
NodeProbs(node) <- value

Arguments

node

An active, discrete NeticaNode whose conditional probability table is to be accessed.

value

The new conditional probability table. See details for the expected dimensions.

Details

Let node be the node of interest and parent1, parent2, ..., parentp, where p is the number of parents. Let pdim = sapply(NodeParents(node), NodeNumStates) be a vector with the number of states for each parent. A parent configuration is defined by assigning each of the parent values to one of its possible states. Each parent configuration defines a (conditional) probability distribution over the possible states of node.

The result of NodeProbs(node) will be an array with dimensions c(pdim, NodeNumStates(node)). The first p dimensions will be named according to the NodeInputNames(node) or the NodeName(parent) if the input names are not set. The last dimension will be named according to the node itself. The dimnames for the resulting array will correspond to the state names.

In the CPTtools package, this known as the CPA format, and tools exist to convert between this form an a two dimensional matrix, or CPF format.

The setter form expects an array of the same dimensions as an argument, although it does not need to have the dimnames set.

Value

A conditional probability array of class c("CPA","array"). See details.

Note

Note that the expression node[...] also accesses the partial or complete node conditional probability table. See Extract.NeticaNode.

All of this assumes that these are discrete nodes, that is is.discrete(node) will return true for both node and all of the parents. If the nodes are continuous, they need to be discritized through the use of NodeLevels.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html: GetNodeProbs_bn(), SetNodeProbs_bn()

See Also

Extract.NeticaNode, NeticaNode, NodeParents(), NodeInputNames(), NodeStates(), CPA, CPF, normalize()

Examples

sess <- NeticaSession()
startSession(sess)
abc <- CreateNetwork("ABC", session=sess)
A <- NewDiscreteNode(abc,"A",c("A1","A2","A3","A4"))
B <- NewDiscreteNode(abc,"B",c("B1","B2","B3"))
C <- NewDiscreteNode(abc,"C",c("C1","C2"))

AddLink(A,B)
AddLink(A,C)
AddLink(B,C)

NodeProbs(A)<-c(.1,.2,.3,.4)
NodeProbs(B) <- normalize(matrix(1:12,4,3))
NodeProbs(C) <- normalize(array(1:24,c(4,3,2)))

Aprobs <- NodeProbs(A)
Bprobs <- NodeProbs(B)
Cprobs <- NodeProbs(C)
stopifnot(
  CPTtools::is.CPA(Aprobs),
  CPTtools::is.CPA(Bprobs),
  CPTtools::is.CPA(Cprobs)
)

DeleteNetwork(abc)
stopSession(sess)

[Package RNetica version 0.8-4 Index]