PnodeStateValues: Accesses the numeric values associated with the state of a...

PnodeStateValuesR Documentation

Accesses the numeric values associated with the state of a parameterized node.

Description

The values are a numeric value (on a standard normal scale) associated with the levels of a discrete Pnode. This function fetches or retrieves the numeric values for the states of node.

Note that the default method for the funciton PnodeParentTvals uses the values of PnodeStateValues on the parent nodes.

Usage

PnodeStateValues(node)
PnodeStateValues(node) <- value

Arguments

node

A Pnode whose levels are to be accessed.

value

A numeric vector of values which should have length length(PnodeStates(node)).

Details

This function behaves differently for discrete and continuous nodes (see isPnodeContinuous). For discrete nodes, the states are numeric values associated with the states. These are used in a number of ways, most importantly, as PnodeParentTvals. Note that the first time the PnodeStateValues() are set, the entire vector must be set. After that point individual values may be changed.

For continuous nodes, the state values are set by setting the PnodeStateBounds for the node. The value is the midpoint of each interval. (Note this produces an infinite state value if one of the state bounds in infinite).

Value

A numeric vector of length length(Pnodetates()), with names equal to the state names. If levels have not be set, NAs will be returned.

Author(s)

Russell Almond

See Also

PnodeStateBounds, Pnode, PnodeStates(), PnodeName(), PnodeStateTitles(), PnodeParentTvals()

Examples

## Not run: 
library(PNetica)##Requires PNetica
sess <- NeticaSession()
startSession(sess)
lnet <- CreateNetwork("LeveledNet", session=sess)

vnode <- NewDiscreteNode(lnet,"volt_switch",c("Off","Reverse","Forwards"))
stopifnot(
  length(PnodeStateValues(vnode))==3,
  names(PnodeStateValues(vnode)) == PnodeStates(vnode),
  all(is.na(PnodeStateValues(vnode)))
)

## Don't run this until the levels for vnode have been set,
## it will generate an error.
try(PnodeStateValues(vnode)[2] <- 0)

PnodeStateValues(vnode) <- 1:3
stopifnot(
  length(PnodeStateValues(vnode))==3,
  names(PnodeStateValues(vnode)) == PnodeStates(vnode),
  PnodeStateValues(vnode)[2]==2
)

PnodeStateValues(vnode)["Reverse"] <- -2

## Continuous nodes get the state values from the bounds.
theta0 <- NewContinuousNode(lnet,"theta0")
stopifnot(length(PnodeStateValues(theta0))==0L)
norm5 <- 
   matrix(c(qnorm(c(.001,.2,.4,.6,.8)),
            qnorm(c(.2,.4,.6,.8,.999))),5,2,
          dimnames=list(c("VH","High","Mid","Low","VL"),
                        c("LowerBound","UpperBound")))
PnodeStateBounds(theta0) <- norm5
PnodeStateValues(theta0)  ## Note these are medians not mean wrt normal!
PnodeStateBounds(theta0)[1,1] <- -Inf
PnodeStateValues(theta0)  ## Infinite value!


DeleteNetwork(lnet)
stopSession(sess)

## End(Not run)

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