Pnode.NeticaNode: Class '"NeticaNode"' as a '"Pnode"'

Pnode.NeticaNodeR Documentation

Class "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.

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 methods are related to the basic node structures and they should operate on all NeticaNode objects, whether they are Pnodes or not.

PnodeNet

signature(net = NeticaNode): Returns the NeticaBN (also Pnet) which contains the node.

PnodeName

signature(net = NeticaNode): Gets the name of the node.

PnodeName<-

signature(net = NeticaNode): Sets the name of the node.

PnodeTitle

signature(net = NeticaNode): Gets the title of the node.

PnodeTitle<-

signature(net = NeticaNode): Sets the title of the node.

PnodeDescription

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

PnodeProbs

signature(net = NeticaNode): Gets the conditional probability table for a node..

PnodeProbs<-

signature(net = NeticaNode): Sets the conditional probability table for a node.

PnodeDescription<-

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

PnodeLabels

signature(net = NeticaNode): Gets the vector of names of the sets to which this node belongs.

PnodeLabels<-

signature(net = NeticaNode): Sets the vector of sets to which the node belongs.

isPnodeContinuous

signature(net = NeticaNode): Returns true or false, depending on whether or not node is continuous.

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

Note

The “Pnode properies”, lnAlphas, betas, Q, rules, link, linkScale, and priorWeight are stored in user fields (NodeUserObj) of the Netica node. A NeticaNode object which has those fields behaves as a Pnode and is suitable for the use with Peanut. The function Pnode will add default values for these fields if they are not set.

To mark a node as a Pnode, it is added to the node set “pnode”. The is.Pnode function checks for this method.

Author(s)

Russell Almond

See Also

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

Base class: NeticaNode.

Mixin class: Pnode.

Generic functions from Peanut package:

Pnode, PnodeNet, PnodeName, PnodeTitle, PnodeDescription, PnodeLabels, PnodeNumParents, PnodeParentNames, PnodeParents, PnodeProbs, as.Pnode, is.Pnode, isPnodeContinuous.

Examples

sess <- NeticaSession()
startSession(sess)

nsnet <- CreateNetwork("NodeSetExample", session=sess)
Ability <- NewDiscreteNode(nsnet,"Ability",c("High","Med","Low"))
EssayScore <- NewDiscreteNode(nsnet,"EssayScore",paste("level",5:0,sep="_"))
Duration <- NewContinuousNode(nsnet,"Duration")

## Pnode, is.Pnode, as.Pnode
stopifnot(!is.Pnode(EssayScore),!is.Pnode(Duration))
EssayScore <- Pnode(EssayScore)
Duration <- as.Pnode(Duration)
stopifnot(is.Pnode(EssayScore),is.Pnode(Duration))

## PnodeNet

stopifnot(PnodeNet(Ability)==nsnet)

## PnodeName, PnodeTitle, PnodeDescription
PnodeTitle(Ability) <- "Student Ability"
PnodeDescription(Ability) <-
"Students who have more ability will have more success on the exam."
stopifnot(PnodeTitle(Ability) == "Student Ability",
PnodeDescription(Ability) ==
"Students who have more ability will have more success on the exam."
)


## PnodeLabels
stopifnot(
  length(PnodeLabels(Ability)) == 0L ## Nothing set yet
)
PnodeLabels(Ability) <- "ReportingVariable"
stopifnot(
  PnodeLabels(Ability) == "ReportingVariable"
)
PnodeLabels(EssayScore) <- c("Observable",PnodeLabels(EssayScore))
stopifnot(
  !is.na(match("Observable",PnodeLabels(EssayScore)))
)
## Make EssayScore a reporting variable, too
PnodeLabels(EssayScore) <- c("ReportingVariable",PnodeLabels(EssayScore))
stopifnot(
  setequal(PnodeLabels(EssayScore),c("Observable","ReportingVariable","pnodes"))
)

## Clear out the node set
PnodeLabels(Ability) <- character()
stopifnot(
  length(PnodeLabels(Ability)) == 0L
)

## PnodeNumParents, PnodeParents

stopifnot(PnodeNumParents(Ability)==0L, PnodeParents(Ability)==list())
PnodeParents(EssayScore) <- list(Ability)
stopifnot(PnodeNumParents(EssayScore)==1L,
          PnodeParents(EssayScore)[[1]]==Ability,
          PnodeParentNames(EssayScore)=="Ability")

DeleteNetwork(nsnet)

## Node Probs
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)


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