PnodeParents {Peanut} | R Documentation |
A parent of a child node is another node which has a link from the parent to the child. This function returns the list of parents parents of the the node. It allows the list of parents for the node to be set, altering the topology of the network (see details).
PnodeParents(node) PnodeParents(node) <- value PnodeNumParents(node) PnodeParentNames(node)
node |
A |
value |
A list of |
At its most basic level, PnodeParents()
reports on the topology
of a network. Suppose we add the links A1 --> B
,
A2 --> B
, and A3 --> B
to the network. Then
PnodeParents(B)
should return list(A1, A2, A3)
. The
order of the inputs is important, because that this determines the
order of the dimensions in the conditional probability table
(BuildTable()
).
The parent list can be set. This can accomplishes a number of different goals: it can replace a parent variable, it can add additional parents, it can remove extra parents, and it can reorder parents. Changing the parents alters the topology of the network. Note that the network must always be acyclic directed graphs. In particular, if changing the parent structure will result in a directed cycle,it will likely raise an error).
PnodeParents
list of Pnode
objects representing the
parents in the order that they will be used to establish dimensions
for the conditional probability table.
The setting variant returns the modified child object.
The expression PnodeNumParents(node)
returns an integer scalar giving
the number of parents of node
.
The expression PnodeParentNames(node)
is a shortcut fo
sapply(PnodeParents(node), PnodeName)
.
Russell Almond
## Not run: library(PNetica) ## Requires PNetica sess <- NeticaSession() startSession(sess) abnet <- CreateNetwork("AB", session=sess) anodes <- NewDiscreteNode(abnet, paste("A",1:3,sep="")) B <- NewDiscreteNode(abnet,"B") ## Should be empty list stopifnot(length(PnodeParents(B))==0) PnodeParents(B) <- anodes stopifnot( length(PnodeParents(B))==3, PnodeParents(B)[[2]] == anodes[[2]] ) ## Reorder nodes PnodeParents(B) <- anodes[c(2:3,1)] stopifnot( length(PnodeParents(B))==3, PnodeName(PnodeParents(B)[[2]])=="A3", all(nchar(names(PnodeParents(B)))==0) ) ## Remove a node. PnodeParents(B) <- anodes[2:1] stopifnot( length(PnodeParents(B))==2, PnodeName(PnodeParents(B)[[2]])=="A1", all(nchar(names(PnodeParents(B)))==0) ) ## Add a node PnodeParents(B) <- anodes[3:1] stopifnot( length(PnodeParents(B))==3, PnodeName(PnodeParents(B)[[3]])=="A1", all(nchar(names(PnodeParents(B)))==0) ) ## Remove all parents PnodeParents(B) <- list() stopifnot( length(PnodeParents(B))==0 ) DeleteNetwork(abnet) stopSession(sess) ## End(Not run)