Pnode.States: States of the '"NeticaNode"' as a '"Pnode"'

Pnode.StatesR Documentation

States of the "NeticaNode" as a "Pnode"

Description

The PNetica package supplies the needed methods so that the RNetica::NeticaNode object is an instance of the Peanut::Pnode object. As a Pnode is nominally parameterized, the are given the special label “pnode” to indicate that this note has parametric information. This page documents the methods which access the states.

Extends

See NeticaNode for a description of the Netica class.

With these methods, NeticaNode now extends Pnode.

All reference classes extend and inherit methods from "envRefClass".

Methods

All methods are implementations of generic functions in the Peanut package. The following functions work with the states associated with the node. Each of the values returned or set is a vector whose length should match the number of states of the node.

PnodeNumStates

signature(node = NeticaNode): Returns the number of states of the node.

PnodeStates

signature(node = NeticaNode): Gets the names of the states of the node.

PnodeStates<-

signature(node = NeticaNode): Sets the number and names of the states of the node. Note that node state names must follow the IDname conventions.

PnodeStateTitles

signature(node = NeticaNode): Gets the titles of the states.

PnodeStateTitles<-

signature(node = NeticaNode): Sets the titles of the states.

PnodeStateDescriptions

signature(node = NeticaNode): Gets the description of the states.

PnodeStateDescriptions<-

(signature(node = NeticaNode): Sets the description of the states.

PnodeStateValues

signature(node = NeticaNode): Gets the vector of real values associated with the states. For continuous nodes, these are calculated from the bounds.

PnodeStateValues<-

signature(node = NeticaNode): Sets the vector of real values associated with the states; the node must be discrete.

PnodeStateBounds

signature(node = NeticaNode): Gets the K by 2 matrix of upper and lower bounds for a continuous node.

PnodeStateBounds<-

signature(node = NeticaNode): Sets the K by 2 matrix of upper and lower bounds for a continuous node. The upper and lower bounds must match, see the documentation in the Peanut package for more information.

Documentation for other methods of the Pnode generic functions for NeticaNode objects can be found in the documentation objects Pnode.NeticaNode and Pnode.Properties.

Note

Netica overrides the NodeLevels to do different things whether the node is continuous or discrete. The functions PnodeStateValues and PnodeStateBounds attempt to untangle these two different use cases. In particular, NodeLevels for a continuous node assumes that the range of the node is chopped into a number of contiguous segments, and what is fed to the function is a list of cut points. Thus, it will encouter problems if the lower bound of one state does not match the upper of the preious one.

Author(s)

Russell Almond

See Also

Other methods of this class Pnode.NeticaNode, Pnode.Properties.

Base class: NeticaNode.

Mixin class: Pnode.

Generic functions from Peanut package:

PnodeNumStates, PnodeStates, PnodeStateTitles, PnodeStateDescriptions, PnodeStateValues, PnodeStateBounds.

Examples

sess <- NeticaSession()
startSession(sess)
curd <- setwd(system.file("testnets",package="PNetica"))

## Making states
anet <- CreateNetwork("Annette", session=sess)

## Discrete Nodes
nodel2 <- NewDiscreteNode(anet,"TwoLevelNode")
stopifnot(
  length(PnodeStates(nodel2))==2,
  PnodeStates(nodel2)==c("Yes","No")
)

PnodeStates(nodel2) <- c("True","False")
stopifnot(
  PnodeNumStates(nodel2) == 2L,
  PnodeStates(nodel2)==c("True","False")
)

nodel3 <- NewDiscreteNode(anet,"ThreeLevelNode",c("High","Med","Low"))
stopifnot(
  PnodeNumStates(nodel3) == 3L,
  PnodeStates(nodel3)==c("High","Med","Low"),
  PnodeStates(nodel3)[2]=="Med"
)

PnodeStates(nodel3)[2] <- "Median"
stopifnot(
  PnodeStates(nodel3)[2]=="Median"
)

PnodeStates(nodel3)["Median"] <- "Medium"
stopifnot(
  PnodeStates(nodel3)[2]=="Medium"
)


DeleteNetwork(anet)

## State Metadata (Titles and Descriptions)

cnet <- CreateNetwork("CreativeNet", session=sess)

orig <- NewDiscreteNode(cnet,"Originality", c("H","M","L"))
PnodeStateTitles(orig) <- c("High","Medium","Low")
PnodeStateDescriptions(orig)[1] <- "Produces solutions unlike those typically seen."

stopifnot(
  PnodeStateTitles(orig) == c("High","Medium","Low"),
  grep("solutions unlike", PnodeStateDescriptions(orig))==1,
  PnodeStateDescriptions(orig)[3]==""
  )

sol <- NewDiscreteNode(cnet,"Solution",
       c("Typical","Unusual","VeryUnusual"))
stopifnot(
  all(PnodeStateTitles(sol) == ""),
  all(PnodeStateDescriptions(sol) == "")
  )

PnodeStateTitles(sol)["VeryUnusual"] <- "Very Unusual"
PnodeStateDescriptions(sol) <- paste("Distance from typical solution",
                      c("<1", "1--2", ">2"))
stopifnot(
  PnodeStateTitles(sol)[3]=="Very Unusual",
  PnodeStateDescriptions(sol)[1] == "Distance from typical solution <1"
  )

DeleteNetwork(cnet)

## State Values
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)
setwd(curd)


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