NodeLevels {RNetica}R Documentation

Accesses the levels associated with a Netica node.

Description

The levels associate a numeric value with the levels of a discrete NeticaNode, or cut a discrete node into a number ordered categories. This function fetches or retrieves the levels for node. See description for more details.

Usage

NodeLevels(node)
NodeLevels(node) <- value

Arguments

node

A NeticaNode whose levels are to be accessed.

value

A numeric vector of values. For discrete nodes, values should have length NodeNumStates(node). For continuous nodes, it can be of any length (except 1) should be in either increasing or decreasing order.

Details

The behavior of the levels depends on whether the node is discrete (is.discrete(node)==TRUE) or continuous (is.discrete(node)==TRUE).

Discrete. For discrete nodes, the levels are associated with the states and provide a numeric summary of the states. In particular, if NodeLevels are set, then it is meaningful to calculate an expected value for the node. The vector returned by NodeLevels() is named with the names of the states, making the association clear. When setting the NodeLevels, it should have length equal to the number of states (NodeNumStates(node)).

Note that the first time the NodeLevels() are set, the entire vector must be set. After that point individual values may be changed.

Continuous. For a continuous node, the levels are used to split the continuous range into intervals (similar in spirit to the function cut()). The levels represent the endpoints of the intervals and should be in either increasing or decreasing order. The values Inf and -Inf are acceptable for the endpoints of the interval. There should be one more level than the desired number of states.

The states of a continuous node are defined by the node levels, and it is not meaningful to try to set NodeStates(), NodeStateTitles() or NodeStateComments().

Setting NodeLevels(node)<-NULL for a continuous node will clear the levels and the states.

Value

For discrete nodes, a numeric vector of length NodeNumStates(), with names equal to the state names. If levels have not be set, NAs will be returned.

For continuous nodes, a numeric vector of length NodeNumStates()+1 with no names, or character(0).

Note

The overloading of node levels is a "feature" of the Netica API. It is not great design, but it probably will be maintained for backwards compatibility.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html: SetNodeLevels_bn()(), GetNodeLevels_bn(), GetNodeNumberStates_bn(), GetNodeStateName_bn(), SetNodeStateNames_bn()

See Also

NewDiscreteNode(), NeticaNode, NodeName(), is.discrete(), is.active(), NodeStateTitles(), NodeStates(), NodeStateComments(),

Examples

sess <- NeticaSession()
startSession(sess)
lnet <- CreateNetwork("LeveledNet", session=sess)

## Discrete Node
vnode <- NewDiscreteNode(lnet,"volt_switch",c("Off","Reverse","Forwards"))
stopifnot(
  length(NodeLevels(vnode))==3,
  names(NodeLevels(vnode)) == NodeStates(vnode),
  all(is.na(NodeLevels(vnode)))
)

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

## End(Not run)

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

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

## Continuous Node
wnode <- NewContinuousNode(lnet,"Weight")
stopifnot(
 length(NodeLevels(wnode))==0,
 NodeNumStates(wnode)==0
)

NodeLevels(wnode) <- c(0, 0.1, 10, Inf)
stopifnot(
 length(NodeStates(wnode))==3,
 NodeNumStates(wnode)==3
)
NodeStates(wnode) <- c("Low","Medium","High")
stopifnot(
 NodeStates(wnode)[3] == "High",
 is.null(names(NodeLevels(wnode)))
)
## Change number of states
NodeLevels(wnode) <- c(0, 0.1, 10, 100, Inf)
stopifnot(
 length(NodeStates(wnode))==4,
 NodeNumStates(wnode)==4,
 all(nchar(NodeStates(wnode))==0)
)
## Clear levels
NodeLevels(wnode) <- c()
stopifnot(
 NodeNumStates(wnode)==0,
 length(NodeStates(wnode))==0
)

DeleteNetwork(lnet)
stopSession(sess)

[Package RNetica version 0.7-2 Index]