powerC: Exponentiate a Matrix via Eigendecomposition

Description Usage Arguments Value Examples

Description

Based on a (contact) matrix C, the function make_powerC generates a function with a single argument power that returns the input matrix raised to that power. Matrix exponentiation is thereby defined via the eigendecomposition of C as C^{power} := E Λ^{power} E^{-1}.

Usage

1
make_powerC(C, normalize = FALSE, truncate = FALSE)

Arguments

C

a square numeric matrix.

normalize

a logical indicating if C should be normalized in advance such that all rows sum to 1 (becomes a transition matrix).

truncate

a logical indicating whether to force entries in the resulting matrix to be non-negative (by truncation at 0).

Value

a function of the power that returns the exponentiated matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Cnorm <- contactmatrix(normalize = TRUE)
powerC <- make_powerC(Cnorm)
powerC(1)
powerC(0)
powers <- c(0, 0.5, 1, 2)
Cp <- lapply(powers, powerC)
if (require("gridExtra"))
    grid.arrange(
        grobs = mapply(plotC, C = Cp, main = paste("power =", powers),
                       SIMPLIFY = FALSE),
        nrow = 2, ncol = 2)

## truncation to enforce non-negative entries
powerC(0.2)  # some entries become negative for small powers
powerC0 <- make_powerC(Cnorm, truncate = TRUE)
powerC0(0.2)

hhh4contacts documentation built on July 4, 2017, 9:44 a.m.