PnetFindNode {PNetica}R Documentation

Finds nodes in a Netica network.

Description

The function PnetFindNode finds a node in a Pnet with the given name. If no node with the specified name found, it will return NULL. The function PnetAllNodes() returns a list of all nodes in the network.

Usage

PnetFindNode(net, name)
PnetAllNodes(net)

Arguments

net

The Pnet to search.

name

A character vector giving the name or names of the desired nodes. Names must follow the IDname protocol.

Details

Although each PnetNode belongs to a single network, a network contains many nodes. Within a network, a node is uniquely identified by its name. However, nodes can be renamed (see NodeName()).

The function PnetAllNodes() returns all the nodes in the network, however, the order of the nodes in the network could be different in different calls to this function.

Value

The Pnode object or list of Pnode objects corresponding to names, or a list of all node objects for PnetAllNodes(). In the latter case, the names will be set to the node names.

Note

PnetNode objects do not survive the life of a Netica session (or by implication an R session). So the safest way to "save" a PnetNode object is to recreate it using PnetFindNode() after the network is reloaded.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html, GetNodeNamed_bn(), GetNetNodes_bn()

See Also

NodeNet() retrieves the network from the node.

Examples

sess <- NeticaSession()
startSession(sess)

tnet <- CreateNetwork("TestNet",sess)
nodes <- NewDiscreteNode(tnet,c("A","B","C"))

nodeA <- PnetFindNode(tnet,"A")
stopifnot (nodeA==nodes[[1]])

nodeBC <- PnetFindNode(tnet,c("B","C"))
stopifnot(nodeBC[[1]]==nodes[[2]])
stopifnot(nodeBC[[2]]==nodes[[3]])

allnodes <- PnetPnodes(tnet)
stopifnot(length(allnodes)==0)

## Need to mark nodes a Pnodes before they will be seen.
nodes <- lapply(nodes,as.Pnode)
allnodes <- PnetPnodes(tnet)
stopifnot(length(allnodes)==3)
stopifnot(any(sapply(allnodes,"==",nodeA))) ## NodeA in there somewhere.

## Not run: 
## Safe way to preserve node and network objects across R sessions.
tnet <- WriteNetworks(tnet,"Tnet.neta")
q(save="yes")
# R
library(RNetica)
sess <- NeticaSession()
startSession(sess)
tnet <- ReadNetworks(tnet,sess)
nodes <- NetworkFindNodes(tnet,as.character(nodes))

## End(Not run)
DeleteNetwork(tnet)

[Package PNetica version 0.8-3 Index]