laplacian: Graph Laplacian Matrices

Description Usage Arguments Details Value Author(s) Examples

View source: R/laplacian.R

Description

Functions for generating graph laplacian matrices based on nearest neighbors in a grid structure or neighbors a certain distance apart.

Usage

1
2

Arguments

dims

A vector containing the dimensions of the underlying grid. One, two and three-dimensional grids are supported.

matrix

A full distance matrix. This can be computed via any distance metric.

window

A scalar denoting the maximum distance at which points are considered neighbors, meaning they share an edge in the graph structure.

Details

Graph Laplacian matrices can be used as generalizing operators in the GPCA framework. These behave like inverse covariances and are useful for recovering edges in the GPCA factors. Laplacians are defined as the degree matrix minus the adjacency matrix for a network structure.

For variables structured as a grid, Laplacians are constructed by placing edges between neighbors in the grid structure. For one dimensional grids (e.g. equally-spaced time points), this is a chain graph. Nearest neighbors for two and three dimensional grids (e.g. image data) are defined using the Chebychev distance. Laplacians for grid structures are scaled to have operator norm one, which is required for use with gpca and sgpca.

Laplacians are constructed from a general distance matrix by placing edges between variables less than or equal to window distance apart. These are returned without scaling to have operator norm one, and must be appropriately scaled before used with gpca and sgpca.

Value

Q

A sparse matrix of the class dgCMatrix.

Author(s)

Frederick Campbell

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#Laplacians on a 1D, 2D, and 3D grid
Q = laplacian(10)
Q = laplacian(c(10,10))
Q = laplacian(c(10,10,10))

#Laplacians computed based on Euclidean distances
data(ozone2)
D = as.matrix(dist(ozone2$lon.lat))
Q = distLaplacian(D,2)
Q = Q/max(eigen(Q,only.values=TRUE)$values)

Example output

Loading required package: Matrix
Loading required package: fields
Loading required package: spam
Loading required package: dotCall64
Loading required package: grid
Spam version 2.1-1 (2017-07-02) is loaded.
Type 'help( Spam)' or 'demo( spam)' for a short introduction 
and overview of this package.
Help for individual functions is also obtained by adding the
suffix '.spam' to the function name, e.g. 'help( chol.spam)'.

Attaching package: 'spam'

The following objects are masked from 'package:base':

    backsolve, forwardsolve

Loading required package: maps

sGPCA documentation built on May 30, 2017, 5:20 a.m.