PnodeProbs: Gets or sets the conditional probability table associated...

PnodeProbsR 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

PnodeProbs(node)
PnodeProbs(node) <- value

Arguments

node

An active, discrete Pnode 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(PnodeParents(node), PnodeNumStates) 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 PnodeProbs(node) will be an array with dimensions c(pdim, PnodeNumStates(node)). The first p dimensions will be named according to the PnodeParentNames(node). 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 CPA.

Note

All of this assumes that these are discrete nodes, that is isPnodeContinuous(node) will return false for both node and all of the parents, or that the continuous nodes have been discritized through the use of PnodeStateBounds.

Author(s)

Russell Almond

See Also

Pnode, BuildTable, CPA, CPF, normalize(), PnodeParents(), PnodeStates()

Examples


## Not run:  ## Requires implementation
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"))

PnodeParents(A) <- list()
PnodeParents(B) <- list(A)
PnodeParents(C) <- list(A,B)

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

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

DeleteNetwork(abc)
stopSession(sess)

## End(Not run)

ralmond/Peanut documentation built on Sept. 19, 2023, 8:27 a.m.