PnodeEvidence: Accesses the value to which a given node has been...

PnodeEvidenceR Documentation

Accesses the value to which a given node has been instantiated.

Description

Inference is a Bayesian network involves setting the state of a particular node to one of its possible states, either because the state has been observed, or because it has been hypothesized. This processis is often called instantiaion. This function returns the value (state) to which the node has been instantiated, or in the setter form set it. Depending on the implementation logic, the beliefs may be immediately updated or be updated on demand.

Usage

PnodeEvidence(node)
PnodeEvidence(node) <- value

Arguments

node

A Pnode object whose instantiated value will be accessed.

value

The value that the node will be instantiated to, see details.

Details

Currently, Peanut supports two ways of representing nodes, discrete and continuous (see isPnodeContinuous). The current PNetica-package implemenation discritizes continuous nodes, using the PnodeStateBounds to map real numbers to states of the observables. Functions implementing these generic functions may treat these values differently.

The behavior depends on the class of the value argument:

character or factor

The character of factor should represent a state of the node. The node will be instantiated to that state.

numeric scalar

For continuous nodes, the node will be instantiated to that value. For discritized continuous nodes, the node will be instantiated to the state in which the value lies (see PnodeStateBounds).

difftime scalar

The value is first converted to a numeric value with units of seconds. This can be overridden in the implementation.

numeric vector of length PnodeNumStates

The number should represent likelihoods, and this will enter appropriate virual evidence for the node.

NULL

This will retract any existing evidence associated with the node.

Value

The getter function PnodeEvidence will return one of the value forms described in details. If the node is not instantiated, it will return NULL.

The setter function PnodeEvidence<- returns the node argument invisibly.

Note

The current options for this function make a lot of sense with Netica. There may be other modes that are not covered for other implementations.

Author(s)

Russell Almond

See Also

The function PnetCompile usually needs to be run before this function has meaning.

The functions PnodeStates and PnodeStateBounds define the legal values for the value argument.

Examples

## Not run: 

library(PNetica) ## Need a specific implementation
sess <- NeticaSession()
startSession(sess)

irt10.base <- ReadNetworks(system.file("testnets", "IRT10.2PL.base.dne",
                                        package="PNetica"),
                           session=sess)
irt10.base <- as.Pnet(irt10.base)  ## Flag as Pnet, fields already set.
irt10.theta <- PnetFindNode(irt10.base,"theta")
irt10.items <- PnetPnodes(irt10.base)
## Flag items as Pnodes
for (i in 1:length(irt10.items)) {
  irt10.items[[i]] <- as.Pnode(irt10.items[[i]])
  
}

BuildAllTables(irt10.base)
PnetCompile(irt10.base) ## Netica requirement

stopifnot (is.na(PnodeEvidence(irt10.items[[1]])))

PnodeEvidence(irt10.items[[1]]) <- "Correct"
stopifnot(PnodeEvidence(irt10.items[[1]])=="Correct")

PnodeEvidence(irt10.items[[1]]) <- NULL
stopifnot (is.na(PnodeEvidence(irt10.items[[1]])))

PnodeEvidence(irt10.items[[1]]) <- c(Correct=.6,Incorrect=.3)
stopifnot(all.equal(PnodeEvidence(irt10.items[[1]]),
                    c(Correct=.6,Incorrect=.3),
                    tol=3*sqrt(.Machine$double.eps) ))

foo <- NewContinuousNode(irt10.base,"foo")

stopifnot(is.na(PnodeEvidence(foo)))

PnodeEvidence(foo) <- 1
stopifnot(PnodeEvidence(foo)==1)

DeleteNetwork(irt10.base)
stopSession(sess)

## End(Not run)

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