NewDiscreteNode {RNetica}R Documentation

Creates (or destroys) a node in a Netica Bayesian network.

Description

Creates a new node in the NeticaBN net. Netica Nodes can be either discrete, in which case a list of states must be given, or continuous, where states are not given. The function DeleteNodes() deletes a single node or a list of nodes.

Usage

NewDiscreteNode(net, names, states = c("Yes","No"))
NewContinuousNode(net, names)
DeleteNodes(nodes)

Arguments

net

A NeticaBN object point to the network where the nodes will be created.

names

A character vector containing the name or names of the new nodes to be created. The names must follow the IDname rules.

states

Either or character vector, or a list of character vectors. If it is a list, its length should be the same as the length of names. The character vectors give the names of the states for the corresponding node. The entries should all correspond to the IDname rules.

nodes

A NeticaNode or list of NeticaNode objects to be deleted. If a list of nodes, all must be from the same network.

Details

Both NewDiscreteNode() and NewContinuousNode() create new nodes in the network net. If names has length greater than 1, multiple nodes are created.

Netica currently supports two types of nodes. Discrete nodes represent nominal variables. Continuous nodes represent real variables. Continuous nodes cannot be changed to discrete nodes (or vise versa) using calls to the API [this is a different from the GUI]. However, a continuous node can be made to behave like a discrete node (or vise versa) by setting the NodeLevels() attribute.

NewDiscreteNode() additionally requires the states argument to set the initial set of states. (These can be changed later through calls to NodeStates()). If states is a character vector, it is used for the state names. If names has length greater than one, all nodes are created with the same set of states. The default values create a collection of binary variables. If states is a list, then each entry should be a character vector providing the list of states for the corresponding new node.

The function NewContinuousNode() creates a new continuous node. It appears as if Netica expects continuous nodes to be used in one of three ways: (1) they can be discretized using NodeLevels(), (2) they can be used as utilities, (3) they can be used as constants. The function NodeKind() can change a nature node (the default) to a constant or utility node. It appears as if Netica will not compile the network unless this is done for all nodes.

The function DeleteNode() deletes a single node or a group of nodes. If multiple nodes are to be deleted in a single call, they must all belong to the same network. Node that any NeticaNode objects that referenced the just deleted nodes will become inactive (see is.active()).

These functions will affect the cache of nodes maintained by the NeticaBN class (net$nodes). The creation functions will add the new nodes to the cache, and the deletion function will remove the nodes from the cache.

Value

For NewDiscreteNode() or NewContinuousNode(), this returns either a single object of class NeticaNode or a list of such objects (depending on the length of names).

For DeleteNodes() a list of inactive NeticaNode objects corresponding to the recently deleted nodes. If a node was not found, a value of NULL will be returned instead. These will be inactive.

Note

Netica nodes internally contain a pointer back to the net they are associated with (see NodeNet()), so most functions involving nodes don't require the net to be named. The node creation functions are an exception.

Most functions involving lists of nodes assume that all nodes come from the same network. Netica will generate an error if this is not the case.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html: NewNode_bn(), DeleteNode_bn(), GetNodeType_bn(), SetNodeLevels_bn()

See Also

CreateNetwork(), NeticaNode, NodeName(), is.discrete(), is.active(), NodeStates(), NodeLevels(), NodeKind()

Examples

sess <- NeticaSession()
startSession(sess)
safetyNet <- CreateNetwork("safetyNet", session=sess)

noded1 <- NewDiscreteNode(safetyNet, "frayed") ## Yes/No
stopifnot(
 NodeName(noded1) == "frayed",
 NodeStates(noded1) == c("Yes", "No"),
 is.discrete(noded1)
 )

## Both variables should have the same set of states
noded23 <- NewDiscreteNode(safetyNet,c("TensionNS","TensionEW"),
            c("High","Med","Low"))
stopifnot(
  all(sapply(noded23,is.active)),
  all(sapply(noded23,is.discrete)),
  NodeNumStates(noded23[[1]]) == 3,
  NodeStates(noded23[[1]])==NodeStates(noded23[[2]])
)

noded45 <- NewDiscreteNode(safetyNet,c("MeshSize","RopeThickness"),
            list(c("Coarse","Fine"),c("Thick","Medium","Thin")))
stopifnot(
  all(sapply(noded45,is.active)),
  all(sapply(noded45,is.discrete)),
  NodeNumStates(noded45[[1]]) == 2,
  NodeNumStates(noded45[[2]]) == 3,
  NodeStates(noded45[[1]])!=NodeStates(noded45[[2]])
)

nodec <- NewContinuousNode(safetyNet, "Area")
stopifnot(
  is.active(nodec),
  is.continuous(nodec),
  NodeName(nodec) == "Area"
)

stopifnot(length(NetworkAllNodes(safetyNet))==6)

DeleteNodes(nodec)
stopifnot(length(NetworkAllNodes(safetyNet))==5)

DeleteNodes(noded45)
stopifnot(length(NetworkAllNodes(safetyNet))==3)

DeleteNetwork(safetyNet)  
stopSession(sess)


[Package RNetica version 0.8-4 Index]