returnFactorVerticesAndEdges {dynamicGraph}R Documentation

The factor vertex list

Description

Create factor vertex and factor edge lists.

Usage

returnFactorVerticesAndEdges(Vertices, factors = NULL, types = "Generator", 
                             factorVertexColor = "default", 
                             factorEdgeColor = "DarkOliveGreen", 
                             factorClasses = validFactorClasses())

Arguments

Vertices The list of Vertices, each containing the class VertexProto.
factors The list of vectors identifying the factors. Each item in the list is a vector of the indices of vertices of a factor.
types The types of the factors. Either a single type or a list of the same length as factors. Each item of types should match the labels of factorClasses, and is used to set the class of the factor vertex.
factorVertexColor The factorVertexColor of the factor vertices.
factorEdgeColor The factorEdgeColor of the factor edges.
factorClasses The valid factorClasses.

Details

The argument factors is a list of vectors identifying the factors, or generators. Each item in the list is a vector with of the indices (or names) of the vertices of a factor, or variables of a generator. A factor vertex is made for each factor, and factor edges from this factor vertex to the vertices of the factor or added to the factor edge list. Also the edges between pairs of the vertices in the factors are returned.

Value

A list with components

FactorVertices The list of factor vertices, each of class containing FactorVertexProto.
FactorEdges The list of factor edge, each of class containing FactorEdgeProto.
PairEdges A matrix with the edges of the graph, two columns with the indices of the vertices of two ends of the edges.

Note

The methods of the vertex list, returnVertexList, also applies for factor lists, and the methods of the edge list, returnEdgeList, also applies for factor edge lists.

Your modifyModel should compute the new factors, generators, when modifying the model. By default only the new factors are computed when a vertex is deleted. Adding and dropping edges requires finding the cliques of the graph from the edges of the graph. Finding the cliques is out of the scope of dynamicGraph.

Author(s)

Jens Henrik Badsberg

Examples


setClass("defaultModelObjectProto", representation(name = "character"))

if (!isGeneric("modifyModel")) {
  if (is.function("modifyModel"))
    fun <- modifyModel
  else
    fun <- function(object, action, name, name.1, name.2, ...)
                    standardGeneric("modifyModel")
  setGeneric("modifyModel", fun)
}

setMethod("modifyModel", signature(object = "defaultModelObjectProto"),
          function(object, action, name, name.1, name.2, ...)
 {
    args <- list(...)
    FactorVertices <- NULL
    FactorEdges <- NULL
    f <- function(type) if(is.null(type)) "" else paste("(", type, ")")
    if (action == "dropEdge") {
       message(paste("Should return an object with the edge from",
                     name.1, f(args$from.type), "to", name.2, f(args$to.type),
                     "deleted from the argument object"))
    } else if (action == "addEdge") {
       message(paste("Should return an object with the edge from",
                     name.1, f(args$from.type), "to", name.2, f(args$to.type),
                     "added to the argument object"))
    } else if (action == "dropVertex")  {
       message(paste("Should return an object with the vertex", 
                     name, f(args$type),
                     "deleted from the argument object"))
       if (!is.null(args$Arguments) && (args$index > 0)
                       && !is.null(args$Arguments$factorVertexList)
                       && !is.null(args$Arguments$vertexList)) {
         x <- (args$Arguments$factorVertexList)
         factors <- lapply(x, function(i) i@vertex.indices)
         types <- lapply(x, function(i) class(i))
         factors <- lapply(factors, function(x) x[x != args$index])
         if (!(is.null(factors))) {
           result <- returnFactorVerticesAndEdges(
                                   args$Arguments$vertexList, factors, types, 
                                   factorClasses = validFactorClasses())
           FactorVertices <- result$FactorVertices
           FactorEdges <- result$FactorEdges
         }
       }
    } else if (action == "addVertex") {
       message(paste("Should return an object with the vertex", 
                     name, f(args$type), args$index, 
                     "added to the argument object"))
    }
    return(list(object = object,
                FactorVertices = FactorVertices,
                FactorEdges = FactorEdges))
 })


[Package Contents]