ParentStates {RNetica}R Documentation

Returns a list of the names of the states of the parents of a Netica node.

Description

This function returns a list each of whose elements is a character vector giving the states of the parent variables (i.e., the result of calling NodeStates) on each of the elements of NodeParents(node)). The names of this list are the names assigned to the edges through NodeInputNames(node), or the names of the parent variables if edge names were not supplied.

Usage

ParentStates(node)
ParentNames(node)

Arguments

node

An active NeticaNode object whose parent states are to be determined.

Value

For ParentStates(node), named list where each element corresponds to the states of a parent variable. If node has no parents, it returns a list of length 0.

The function ParentNames(node) returns names(ParentNames(node), only is faster.

Note

This is a slightly more sophisticated version of lapply(NodeParents(node), NodeStates). It does minimal checking so that it can be fast.

Author(s)

Russell Almond

See Also

NodeStates(), NodeParents(), NodeInputNames()

Examples

sess <- NeticaSession()
startSession(sess)
abc1 <- CreateNetwork("ABC1", session=sess)
A <- NewDiscreteNode(abc1,"A",c("A1","A2","A3","A4"))
B <- NewDiscreteNode(abc1,"B",c("B1","B2","B3"))
C <- NewDiscreteNode(abc1,"C",c("C1","C2"))

stopifnot(
  length(ParentStates(A)) == 0
)

AddLink(A,B)

Bpars <- ParentStates(B)
stopifnot(
  length(Bpars) == 1,
  names(Bpars) == "A",
  Bpars$A==NodeStates(A)
)

AddLink(A,C)
AddLink(B,C)

NodeInputNames(C) <- c("A_type","B_type")

Cpars <- ParentStates(C)
stopifnot(
  length(Cpars) == 2,
  names(Cpars) == c("A_type","B_type"),
  Cpars[[1]]==NodeStates(A),
  Cpars$B_type==NodeStates(B)
)

DeleteNetwork(abc1)
stopSession(sess)

[Package RNetica version 0.8-2 Index]