Learn R Programming

LaMa (version 1.0.0)

viterbi_g: Viterbi algorithm for decoding states of inhomogeneous HMMs

Description

Viterbi algorithm for decoding states of inhomogeneous HMMs

Usage

viterbi_g(delta, Gamma, allprobs)

Value

Vector of decoded states of length n

Arguments

delta

Initial distribution of length N

Gamma

Array of transition probability matrices of dimension c(N,N,n-1), as in a time series of length n, there are only n-1 transitions. If you provide an array of dimension c(N,N,n), the first slice will be ignored.

allprobs

Matrix of state-dependent probabilities/ density values of dimension c(n, N)

Examples

Run this code
delta = c(0.5, 0.5)
Gamma = array(dim = c(2,2,99))
for(t in 1:99){
  gammas = rbeta(2, shape1 = 0.4, shape2 = 1)
  Gamma[,,t] = matrix(c(1-gammas[1], gammas[1], 
                      gammas[2], 1-gammas[2]), nrow = 2, byrow = TRUE)
}
allprobs = matrix(runif(200), nrow = 100, ncol = 2)
states = viterbi_g(delta, Gamma, allprobs)

Run the code above in your browser using DataLab