CopyNodes {RNetica} | R Documentation |
This function either copies nodes from one net to another or duplicates nodes within the same network.
CopyNodes(nodes, newnamelist = NULL, newnet = NULL, options = character(0))
nodes |
A list of active |
newnamelist |
If supplied, this should be character vector with the same length as
|
newnet |
If supplied, it should be an active |
options |
A character vector of options, with each element being one of the
options. Currently, the only supported options are
|
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:
"no_tables"
— The conditional probability tables of
the nodes (see NodeProbs()
) will not be copied, and new
tables will need to be set in the new network.
"no_links"
— The links going into the nodes
will
not be copied. Note that the "no_links"
option implies the
"no_tables"
option, so both do not need to be specified.
A list containing the new nodes (or just the new node, if there is only one).
There may be some information that is not copied. For example, the
NodeSets()
information is not copied.
Russell Almond
http://norsys.com/onLineAPIManual/index.html: CopyNodes_bn()
CopyNetworks()
, NeticaNode
,
NeticaBN()
, NodeProbs()
,
NodeParents()
, AbsorbNodes()
,
DeleteNodes()
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)