hhh4contacts (version 0.13.1)

powerC: Exponentiate a Matrix via Eigendecomposition

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 \Lambda^{power} E^{-1}\).

Usage

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

Value

a function of the power

that returns the exponentiated matrix.

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).

Examples

Run this code
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)

Run the code above in your browser using DataLab