powerC | R Documentation |
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}
.
make_powerC(C, normalize = FALSE, truncate = FALSE)
C |
a square numeric matrix. |
normalize |
a logical indicating if |
truncate |
a logical indicating whether to force entries in the resulting matrix to be non-negative (by truncation at 0). |
a function of the power
that returns the exponentiated matrix.
Cnorm <- contactmatrix(normalize = TRUE)
powerC <- make_powerC(Cnorm)
powerC(1)
zapsmall(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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.