% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/decoding_functions.R
\name{viterbi_g}
\alias{viterbi_g}
\title{Viterbi algorithm for state decoding in inhomogeneous HMMs}
\usage{
viterbi_g(delta, Gamma, allprobs, trackID = NULL, mod = NULL)
}
\arguments{
\item{delta}{initial distribution; either
\itemize{
  \item a vector of length \code{nStates}, or
  \item a matrix of dimension \code{c(nTracks, nStates)} if \code{trackID} is provided
}}

\item{Gamma}{array of transition probability matrices of dimension \code{c(nStates, nStates, nObs)},
where the first slice of each track is ignored as there is no transition into the start of a track.
For a single track, an array of dimension \code{c(nStates, nStates, nObs-1)} is also accepted.}

\item{allprobs}{matrix of state-dependent probabilities or density values of dimension \code{c(nObs, nStates)}}

\item{trackID}{optional vector of length \code{nObs} containing \code{nTracks} unique IDs that separate tracks}

\item{mod}{optional model object containing \code{delta}, \code{Gamma}, \code{allprobs}, and
optionally \code{trackID}. When using \code{RTMB::MakeADFun} or \code{\link{qreml}} with
\code{\link{forward_g}} in the likelihood, these are reported automatically after model fitting
and the object returned by \code{RTMB::report()} or \code{\link{qreml}} can be passed directly.}
}
\value{
vector of decoded states of length \code{nObs}
}
\description{
The Viterbi algorithm decodes the most probable state sequence of an HMM.
}
\examples{
delta = c(0.5, 0.5)
Gamma = tpm_g(runif(10), matrix(c(-2,-2,1,-1), nrow = 2))
allprobs = matrix(runif(20), nrow = 10, ncol = 2)
states = viterbi_g(delta, Gamma[,,-1], allprobs)
}
\seealso{
Other decoding functions: 
\code{\link{stateprobs}()},
\code{\link{stateprobs_g}()},
\code{\link{stateprobs_p}()},
\code{\link{viterbi}()},
\code{\link{viterbi_p}()}
}
\concept{decoding functions}
