...
 
Commits (2)
^.*\.Rproj$
^\.Rproj\.user$
.Rproj.user
.Rhistory
.RData
.Ruserdata
Package: garm
Type: Package
Title: Graphs as Riemannian manifolds
Version: 0.1.0
Author: Corson N. Areshenkoff
Maintainer: Corson N. Areshenkoff <areshenk@protonmail.com>
Description: Implements several PDE models on graphs, and other constructions
arising from the view of graphs as discrete Riemannian manifolds.
Depends: igraph
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
export(heatkern)
#' Brain network graph
#'
#' A small sample graph created from fMRI bold signal using the graphical lasso.
#'
#' @name boldgraph
#' @docType data
#' @author Corson N. Areshenkoff \email{areshenk@protonmail.com}
#' @keywords data
NULL
heatkern.kernel <- function(x, time = NULL){
if (is.null(time)){
stop('Must specify time points')
}
if (!is.numeric(time) & !is.vector(time)){
stop('time must be a numeric vectors')
}
# Get normalized laplacian
L <- laplacian_matrix(x, normalized = T, sparse = F)
# Spectral decomposition
eig <- eigen(L)
lambda <- eig$values
V <- eig$vectors
# Compute heat kernel
hk <- sapply(time, function(i) V %*% diag(exp(-i * lambda)) %*% t(V),
simplify = 'array')
return(hk)
}
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) {
if (!is.numeric(m) || length(m) != 1 || m %% 1 != 0 || m <= 0){
stop('m must be an integer >= 1')
}
# Get normalized laplacian
L <- laplacian_matrix(x, normalized = T, sparse = F)
# Spectral decomposition
eig <- eigen(L)
lambda <- eig$values
V <- eig$vectors
# Compute heat content invariance
qm <- sapply(1:m, function(i) {
sum(colSums(V^2) * (-lambda)^i / factorial(i))
})
return(qm)
}
#' 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.
#'
#' @param x An igraph object
#' @param stat The type of feature to return. See details.
#' @param ... Further arguments. See details
#' @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}}
#' \item{"trace": }{Returns the trace of the heat kernel at time points given
#' by an integer vector \code{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
#' expansion to return.}
#' }
#' @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
#' \code{time}}
#' \item{"heatcontent": }{A numeric vector with length equation to \code{m}}
#' }
#' @author Corson N. Areshenkoff \email{areshenk@protonmail.com}
heatkern <- function(x, stat = 'kernel', ...){
if (class(x) != 'igraph'){
stop('Input x must be of class igraph')
}
# Wrapper
h <- switch(method,
kernel = heatkern.kernel(x, ...),
trace = heatkern.trace(x, ...),
heatcontent = heatkern.heatcontent(x, ...))
return(drop(h))
}
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 4
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/boldgraph.R
\docType{data}
\name{boldgraph}
\alias{boldgraph}
\title{Brain network graph}
\description{
A small sample graph created from fMRI bold signal using the graphical lasso.
}
\author{
Corson N. Areshenkoff \email{areshenk@protonmail.com}
}
\keyword{data}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/heatkern.R
\name{heatkern}
\alias{heatkern}
\title{Heat equation on a graph}
\usage{
heatkern(x, stat = "kernel", ...)
}
\arguments{
\item{x}{An igraph object}
\item{stat}{The type of feature to return. See details.}
\item{...}{Further arguments. See details}
}
\value{
\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
\code{time}}
\item{"heatcontent": }{A numeric vector with length equation to \code{m}}
}
}
\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.
}
\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}}
\item{"trace": }{Returns the trace of the heat kernel at time points given
by an integer vector \code{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
expansion to return.}
}
}
\author{
Corson N. Areshenkoff \email{areshenk@protonmail.com}
}