NetworkFindNode {RNetica}R Documentation

Finds nodes in a Netica network.

Description

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

Usage

NetworkFindNode(net, name)
NetworkAllNodes(net)

Arguments

net

The NeticaBN to search.

name

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

Details

Although each NeticaNode 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 NetworkAllNodes() 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.

Starting with RNetica version 0.5, NeticaBN objects keep a cache of node objects in the environment net$nodes. In particular, the methods net$findNode() will search the cache, and net$listNodes() will list the names of the nodes in the cache. Also, net$nodes$nodename or net$nodes[["nodename"]] will fetch the cached node (if it exists) or return NULL if it does not.

Nodes that are created in RNetica, using NewDiscreteNode or NewContinuousNode are automatically added to the cache. This is also true of other functions which return NeticaNode objects. For example, NodeParents(node) will add the parents of node to the cache if they are not there already.

A potential problem arises when the network is read from a file using ReadNetworks. This function does not automatically cache the nodes. Calling NetworkFindNode will add the nodes to the cache. Calling NetworkAllNodes will add all nodes to the cache. Calling NetworkNodesInSet can be used to pull just a subsetof nodes into the cache.

Value

The NeticaNode object or list of NeticaNode objects corresponding to names, or a list of all node objects for NetworkAllNodes(). In the latter case, the ‘names’ attribute of the returned list will be set to the node names.

Note

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

Author(s)

Russell Almond

References

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

See Also

NeticaBN talks more about the node cache and has other functions for manipulating it.

NetworkNodesInSet can be used to find a labeled subset of nodes.

NodeNet() retrieves the network from the node.

Examples

sess <- NeticaSession()
startSession(sess)

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

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

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

allnodes <- NetworkAllNodes(tnet)
stopifnot(length(allnodes)==3)
stopifnot(is.element(nodeA,allnodes)) ## 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, session=sess)
nodes <- NetworkFindNodes(tnet,tnet$listNodes())

## End(Not run)
DeleteNetwork(tnet)
stopSession(sess)

[Package RNetica version 0.7-1 Index]