CopyNodes {RNetica}R Documentation

Copies or duplicates nodes in a Netica network.

Description

This function either copies nodes from one net to another or duplicates nodes within the same network.

Usage

CopyNodes(nodes, newnamelist = NULL, newnet = NULL, options = character(0))

Arguments

nodes

A list of active NeticaNode objects all from the same network.

newnamelist

If supplied, this should be character vector with the same length as nodes giving the new names for the nodes.

newnet

If supplied, it should be an active NeticaBN which is the destination for the new nodes. If this argument is NULL the nodes will be duplicated within the original network.

options

A character vector of options, with each element being one of the options. Currently, the only supported options are "no_tables" (do not copy the conditional probability tables for the nodes) and "no_links" (do not duplicate the links, which implies do not copy tables).

Details

The nodes in the first argument will be copied into a new network as specified by newnet. If newnet is not specified or if it the same as the network from which nodes come, then the nodes will be duplicated instead of copied.

If the nodes are duplicated, then will be given new names. The default Netica behavior for new names is to append a number to the end of the node name, or to increment an existing number. If newnamelist is supplied, these names will be used instead of the add a number convention. Supplying newnamelist will change the names of the nodes when copying from one network to another.

When nodes are copied links going into the node are copied as well. Thus if there is a link A -> B in the network and B is copied into the same network, then there will a link A -> B1 to the new node. If B is copied into a new network, the link will be there but not attached, as if NodeParents(B1)[A] <- NULL had been called.

The argument options allows control over what is copied. The currently supported options are:

Value

A list containing the new nodes (or just the new node, if there is only one).

Note

There may be some information that is not copied. For example, the NodeSets() information is not copied.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html: CopyNodes_bn()

See Also

CopyNetworks(), NeticaNode, NeticaBN(), NodeProbs(), NodeParents(), AbsorbNodes(), DeleteNodes()

Examples

sess <- NeticaSession()
startSession(sess)
System <- ReadNetworks(file.path(library(help="RNetica")$path,
                           "sampleNets","System.dne"), session=sess)

EMTask1a <- ReadNetworks(file.path(library(help="RNetica")$path,
                           "sampleNets","EMTask1a.dne"), session=sess)

student1 <- CopyNetworks(System, "Student1")
student1.sysnodes <- NetworkAllNodes(student1)

student1.t1anodes <- CopyNodes(NetworkAllNodes(EMTask1a),newnet=student1)

## Copied, new nodes have the same names as the old nodes.
stopifnot(
  setequal(names(NetworkAllNodes(EMTask1a)),
           names(student1.t1anodes))
)

## The nodes in the evidence model have stub connections to the nodes in
## the system model.  Need to link them up.
stopifnot(
  any(sapply(NodeParents(student1.t1anodes[[1]]),NodeKind) == "Stub"),
  any(sapply(NodeParents(student1.t1anodes[[2]]),NodeKind) == "Stub")
)


student1.allnodes <- NetworkAllNodes(student1)
for (node in student1.t1anodes) {
  stubs <- sapply(NodeParents(node),NodeKind) == "Stub"
  NodeParents(node)[stubs] <- student1.allnodes[NodeInputNames(node)[stubs]]
}
stopifnot(
  sapply(NodeParents(student1.t1anodes[[1]]),NodeKind) != "Stub",
  sapply(NodeParents(student1.t1anodes[[2]]),NodeKind) !="Stub"
)

## Duplicate these nodes.
student1.t1xnodes <- CopyNodes(student1.t1anodes)

## Autonaming increments the numbers.  
stopifnot(
  setequal(names(student1.t1xnodes),c("Obs1a3","Obs1a4"))
)

## Duplicate and rename.
student1.t1cnodes <- CopyNodes(student1.t1anodes,c("Obs1c1","Obs1c2"))

stopifnot(
  setequal(names(student1.t1cnodes),c("Obs1c1","Obs1c2"))
)
## Duplicated nodes have real not stub connections.
stopifnot(
  sapply(NodeParents(student1.t1cnodes[[1]]),NodeKind) != "Stub",
  sapply(NodeParents(student1.t1cnodes[[2]]),NodeKind) !="Stub"
)


DeleteNetwork(list(System,student1,EMTask1a))
stopSession(sess)


[Package RNetica version 0.7-3 Index]