Nothing
#' Discrete-time matrix convolution product
#'
#' @description Computes the discrete-time convolution product \eqn{A * B} of
#' two matrix-valued functions \eqn{A} and \eqn{B} defined on
#' \eqn{\mathbb{N}}{N} (Barbu and Limnios, 2008, Definition 3.5, p. 48):
#' \deqn{(A * B)(k) = \sum_{l = 0}^{k} A(k - l)\, B(l), \quad k \in \mathbb{N},}{(A * B)(k) = sum_{l = 0}^{k} A(k - l) B(l), k in N,}
#' where \eqn{A(k - l) B(l)} is the usual matrix product.
#'
#' @details Notation (see [smmR-package] for the complete description of the
#' models): \eqn{s = \textrm{card}(E)}{s = card(E)} is the number of states, and
#' a matrix-valued function on \eqn{\{0, \dots, k\}}{{0, ..., k}} is an array of
#' dimension \eqn{(s, s, k + 1)} whose slice \eqn{l + 1} is its value at time
#' \eqn{l}.
#'
#' The slice \eqn{l + 1} of `a` (or `b`) is the matrix \eqn{A(l)} (or
#' \eqn{B(l)}), for \eqn{l = 0, \dots, k}{l = 0, ..., k}. This is the format of the kernel
#' returned by [get.kernel] and of the outputs of [get.H], [get.psi] and
#' [get.P].
#'
#' The matrix convolution product is associative but not commutative. Its
#' neutral element is \eqn{\delta I}{delta I}, i.e. the identity matrix at
#' time 0 and the null matrix at times \eqn{k > 0} (Lemma 3.1, p. 48). The
#' \eqn{n}-fold convolution of the semi-Markov kernel, \eqn{q^{(n)}}{q^(n)}
#' (Definition 3.6, p. 48), is obtained by applying this function
#' \eqn{n - 1} times (see [get.psi]).
#'
#' @param a A numeric array of dimension \eqn{(s, s, k + 1)}.
#' @param b A numeric array of dimension \eqn{(s, s, k + 1)}.
#'
#' @return A numeric array of dimension \eqn{(s, s, k + 1)} whose slice
#' \eqn{l + 1} is the matrix \eqn{(A * B)(l)}, for
#' \eqn{l = 0, \dots, k}{l = 0, ..., k}.
#'
#' @references
#' V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov
#' Models Toward Applications - Their Use in Reliability and DNA Analysis.
#' New York: Lecture Notes in Statistics, vol. 191, Springer.
#'
#' @seealso [convolution], [get.kernel], [get.psi], [get.P]
#'
#' @examples
#' states <- c("a", "b", "c")
#' ptrans <- matrix(c(0, 0.6, 0.4,
#' 0.5, 0, 0.5,
#' 0.7, 0.3, 0), nrow = 3, byrow = TRUE)
#' param <- matrix(c(0.3, 2, 0.6,
#' NA, NA, 0.8), nrow = 3)
#' x <- smmparametric(states = states, init = c(1/3, 1/3, 1/3),
#' ptrans = ptrans, type.sojourn = "fi",
#' distr = c("geom", "pois", "dweibull"), param = param)
#'
#' q <- get.kernel(x, k = 10)
#' q2 <- matrixConvolution(q, q) # q^(2): two jumps
#' q2[, , 4] # probabilities of two jumps at time 3
#'
#' @export
#'
matrixConvolution <- function(a, b) {
#############################
# Checking parameter a
#############################
if (!(is.numeric(a) & !anyNA(a) & is.array(a) & !is.matrix(a) & (dim(a)[1] == dim(a)[2]))) {
stop("'a' must be a numeric array of dimension (s, s, k+1)")
}
#############################
# Checking parameter b
#############################
if (!(is.numeric(b) & !anyNA(b) & is.array(b) & !is.matrix(b) & (dim(b)[1] == dim(b)[2]))) {
stop("'b' must be a numeric array of dimension (s, s, k+1)")
}
if (!((dim(a)[1] == dim(b)[1]) & (dim(a)[3] == dim(b)[3]))) {
stop("'a' and 'b' must have the same dimensions")
}
c <- C_matrixConvolution(a, b)
return(c)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.