Learn R Programming

nimble (version 1.4.0)

expAv: Matrix Exponential times a vector

Description

Compute the combined term expm(A) %*% v to avoid a full matrix exponentiation.

Usage

expAv(A, v, tol = 1e-08, rescaleFreq = 10, Nmax = 10000, sparse = TRUE)

Value

the result as a vector.

Arguments

A

Square matrix.

v

vector to multiply by the matrix exponential exp(A) %*% v.

tol

level of accuracy required (default = 1e-8).

rescaleFreq

How frequently should the terms be scaled to avoid underflow/overflow (default = 10).

Nmax

Maximum number of iterations to compute (default = 10000).

sparse

(logical) specify if the matrix may be sparse and to do sparse computation (default = TRUE).

Author

Paul van Dam-Bates

Details

For large matrix exponentials it is much more efficient to compute exp(A) %*% v, than to actually compute the entire matrix exponential.

This function follows the function expAv from the R package RTMB (Kristensen, 2025), and theory outlined in Sherlock (2021). It is developed for working with continuous times Markov chains. If using the matrix exponential to create a transition probability matrix in a HMM context just once, this function may be slower than the one time call to compute the full matrix exponentiation. If a full matrix exponentiation is required, refer to expm to compute. Choosing sparse = TRUE will check which values of A are non-zero and do sparse linear algebra. Note that for computation efficiency matrix uniformization is done by A* = A + rho I, where rho = max(abs(diag(A))); see Algorithm 2' in Sherlock (2021). When the row sums of the matrix are not zero, then uniformization is not done, and the number of iterations to reach tolerance are approximated based on the a bound of the spectrum, similar to RTMB (Kristensen, 2025).

References

Sherlock, C. (2021). Direct statistical inference for finite Markov jump processes via the matrix exponential. Computational Statistics, 36(4), 2863-2887.

Kristensen K (2025). _RTMB: 'R' Bindings for 'TMB'_. R package version 1.7, commit 6bd7a16403ccb4d3fc13ff7526827540bf27b352, <https://github.com/kaskr/RTMB>.

Examples

Run this code
A <- rbind(c(-1, 0.25, 0.75), c(0, -2, 2), c(0.25, 0.25, -0.5))
v <- c(0.35, 0.25, 0.1)
expAv(A, v)

Run the code above in your browser using DataLab