% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/decoding_functions.R
\name{viterbi}
\alias{viterbi}
\title{Viterbi algorithm for state decoding in HMMs}
\usage{
viterbi(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}{transition probability matrix; either
\itemize{
  \item a matrix of dimension \code{c(nStates, nStates)},
  \item an array of dimension \code{c(nStates, nStates, nTracks)} if \code{trackID} is provided, or
  \item an array of dimension \code{c(nStates, nStates, nObs)} for time-varying transition probabilities, in which case \code{\link{viterbi_g}} is called internally
}}

\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}} 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 = matrix(c(0.9, 0.1, 0.2, 0.8), nrow = 2, byrow = TRUE)
allprobs = matrix(runif(200), nrow = 100, ncol = 2)
states = viterbi(delta, Gamma, allprobs)
}
\seealso{
Other decoding functions: 
\code{\link{stateprobs}()},
\code{\link{stateprobs_g}()},
\code{\link{stateprobs_p}()},
\code{\link{viterbi_g}()},
\code{\link{viterbi_p}()}
}
\concept{decoding functions}
