### Conduction and fixes

parent aaa1c9ae
 heatkern.kernel <- function(x, time = NULL){ heatkern.kernel <- function(x, time = NULL, ...){ if (is.null(time)){ stop('Must specify time points') ... ... @@ -8,7 +8,7 @@ heatkern.kernel <- function(x, time = NULL){ } # Get normalized laplacian L <- laplacian_matrix(x, normalized = T, sparse = F) L <- laplacian_matrix(x, normalized = F, sparse = F) # Spectral decomposition eig <- eigen(L) ... ... @@ -22,13 +22,13 @@ heatkern.kernel <- function(x, time = NULL){ return(hk) } heatkern.trace <- function(x, time = NULL){ heatkern.trace <- function(x, time = NULL, ...){ hk.mat <- heatkern.kernel(x, time) hk.trace <- apply(hk.mat, 3, function(i) sum(diag(i))) return(hk.trace) } heatkern.heatcontent <- function(x, m = 1) { heatkern.heatcontent <- function(x, m = 1, ...) { if (!is.numeric(m) || length(m) != 1 || m %% 1 != 0 || m <= 0){ stop('m must be an integer >= 1') ... ... @@ -51,3 +51,13 @@ heatkern.heatcontent <- function(x, m = 1) { } heatkern.conduction <- function(x, time = NULL, init = NULL, ...){ hk.mat <- heatkern.kernel(x, time) if (!length(init) == dim(hk.mat)){ stop('Length of init must match number of vertices') } init <- matrix(as.numeric(init), ncol = 1) return(apply(hk.mat, 3, function(i) i %*% init)) }
 #' Heat equation on a graph #' #' Runs the heat equation on an igraph object and optionally returns several #' features describing the conduction of heat along the edges of the graph. #' features describing the conduction of heat throughout the graph. #' #' @param x An igraph object #' @param stat The type of feature to return. See details. ... ... @@ -10,20 +10,24 @@ #' the heat equation on a finite graph. Available statistics include #' \itemize{ #' \item{"kernel": }{Returns the heat kernel (the solution to the heat equation) #' evaluated at time points given by an integer vector \code{time}} #' evaluated at time points given by a vector "time"} #' \item{"trace": }{Returns the trace of the heat kernel at time points given #' by an integer vector \code{time}.} #' by a vector "time".} #' \item{"heatcontent": }{Returns the heat content invariant of the graph (Bai, 2007). #' Requires an integer \code{m} giving the maximum coefficient of the polynomial #' Requires an integer "m" giving the maximum coefficient of the polynomial #' expansion to return.} #' \item{"conduction": }{Simulates the conduction of heat across the vertices #' of the graph given a numeric vector "init" of initial temperatures and a #' vector "t" of time points.} #' } #' @return \itemize{ #' \item{"kernel": }{A square matrix with dimension equal to the number of nodes #' in x. If more than one time point is specified, a 3d array whose third #' coordinate is time.} #' \item{"trace": }{A numeric vector with length equation to the length of #' \item{"trace": }{A numeric vector with length equal to the length of #' \code{time}} #' \item{"heatcontent": }{A numeric vector with length equation to \code{m}} #' \item{"conduction: "}{A vertices-by-time matrix of vertex temporatures.} #' } #' @author Corson N. Areshenkoff \email{areshenk@protonmail.com} ... ... @@ -37,7 +41,8 @@ heatkern <- function(x, stat = 'kernel', ...){ h <- switch(method, kernel = heatkern.kernel(x, ...), trace = heatkern.trace(x, ...), heatcontent = heatkern.heatcontent(x, ...)) heatcontent = heatkern.heatcontent(x, ...), conduction = heatkern.conduction(x, ...)) return(drop(h)) }
 ... ... @@ -18,26 +18,30 @@ heatkern(x, stat = "kernel", ...) \item{"kernel": }{A square matrix with dimension equal to the number of nodes in x. If more than one time point is specified, a 3d array whose third coordinate is time.} \item{"trace": }{A numeric vector with length equation to the length of \item{"trace": }{A numeric vector with length equal to the length of \code{time}} \item{"heatcontent": }{A numeric vector with length equation to \code{m}} \item{"conduction: "}{A vertices-by-time matrix of vertex temporatures.} } } \description{ Runs the heat equation on an igraph object and optionally returns several features describing the conduction of heat along the edges of the graph. features describing the conduction of heat throughout the graph. } \details{ Functions computes several statistics derived from the solution to the heat equation on a finite graph. Available statistics include \itemize{ \item{"kernel": }{Returns the heat kernel (the solution to the heat equation) evaluated at time points given by an integer vector \code{time}} evaluated at time points given by a vector "time"} \item{"trace": }{Returns the trace of the heat kernel at time points given by an integer vector \code{time}.} by a vector "time".} \item{"heatcontent": }{Returns the heat content invariant of the graph (Bai, 2007). Requires an integer \code{m} giving the maximum coefficient of the polynomial Requires an integer "m" giving the maximum coefficient of the polynomial expansion to return.} \item{"conduction": }{Simulates the conduction of heat across the vertices of the graph given a numeric vector "init" of initial temperatures and a vector "t" of time points.} } } \author{ ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment