Ahidden Markov model (HMM) is aMarkov model in which the observations are dependent on a latent (orhidden)Markov process (referred to as). An HMM requires that there be an observable process whose outcomes depend on the outcomes of in a known way. Since cannot be observed directly, the goal is to learn about state of by observing. By definition of being a Markov model, an HMM has an additional requirement that the outcome of at time must be "influenced" exclusively by the outcome of at and that the outcomes of and at must be conditionally independent of at given at time. Estimation of the parameters in an HMM can be performed usingmaximum likelihood estimation. For linear chain HMMs, theBaum–Welch algorithm can be used to estimate parameters.
Hidden Markov models are known for their applications tothermodynamics,statistical mechanics,physics,chemistry,economics,finance,signal processing,information theory,pattern recognition—such asspeech recognition,[1]handwriting recognition,gesture recognition,[2]part-of-speech tagging, musical score following,[3]partial discharges[4] andbioinformatics.[5][6]
Let and be discrete-timestochastic processes and. The pair is ahidden Markov model if
Let and be continuous-time stochastic processes. The pair is ahidden Markov model if
The states of the process (resp. are calledhidden states, and (resp. is calledemission probability oroutput probability.

In its discrete form, a hidden Markov process can be visualized as a generalization of theurn problem with replacement (where each item from the urn is returned to the original urn before the next step).[7]
In a room that is not visible to an observer there is a genie. The room contains urns X1, X2, X3, ... each of which contains a known mix of balls, with each ball having a unique label y1, y2, y3, ... . The genie chooses an urn in that room and randomly draws a ball from that urn. It then puts the ball onto a conveyor belt, where the observer can observe the sequence of the balls but not the sequence of urns from which they were drawn.
The genie has some procedure to choose urns:
Therefore, this is called aMarkov process. It can be described by the upper part of Figure 1.
The Markov process cannot be observed, only the sequence of labeled balls, thus this arrangement is called ahidden Markov process. This is illustrated by the lower part of the diagram shown in Figure 1, where one can see that balls y1, y2, y3, y4 can be drawn at each state. Even if the observer knows the composition of the urns and has just observed a sequence of three balls,e.g. y1, y2 and y3 on the conveyor belt, the observer still cannot besure which urn (i.e., at which state) the genie has drawn the third ball from. However, the observer can work out other information, such as the likelihood that the third ball came from each of the urns.
Consider two friends, Alice and Bob, who live far apart from each other and who talk together daily over the telephone about what they did that day. Bob is only interested in three activities: walking in the park, shopping, and cleaning his apartment. The choice of what to do is determined exclusively by the weather on a given day. Alice has no definite information about the weather, but she knows general trends. Based on what Bob tells her he did each day, Alice tries to guess what the weather must have been like.
Alice believes that the weather operates as a discreteMarkov chain. There are two states, "Rainy" and "Sunny", but she cannot observe them directly, that is, they arehidden from her. On each day, there is a certain chance that Bob will perform one of the following activities, depending on the weather: "walk", "shop", or "clean". Since Bob tells Alice about his activities, those are theobservations. The entire system is that of a hidden Markov model (HMM).
Alice knows the general weather trends in the area, and what Bob likes to do on average. In other words, the parameters of the HMM are known. They can be represented as follows inPython:
states=("Rainy","Sunny")observations=("walk","shop","clean")start_probability={"Rainy":0.6,"Sunny":0.4}transition_probability={"Rainy":{"Rainy":0.7,"Sunny":0.3},"Sunny":{"Rainy":0.4,"Sunny":0.6},}emission_probability={"Rainy":{"walk":0.1,"shop":0.4,"clean":0.5},"Sunny":{"walk":0.6,"shop":0.3,"clean":0.1},}
In this piece of code,start_probability represents Alice's belief about which state the HMM is in when Bob first calls her (all she knows is that it tends to be rainy on average). The particular probability distribution used here is not the equilibrium one, which is (given the transition probabilities) approximately{'Rainy': 0.57, 'Sunny': 0.43}. Thetransition_probability represents the change of the weather in the underlying Markov chain. In this example, there is only a 30% chance that tomorrow will be sunny if today is rainy. Theemission_probability represents how likely Bob is to perform a certain activity on each day. If it is rainy, there is a 50% chance that he is cleaning his apartment; if it is sunny, there is a 60% chance that he is outside for a walk.

A similar example is further elaborated in theViterbi algorithm page.
The diagram below shows the general architecture of an instantiated HMM. Each oval shape represents a random variable that can adopt any of a number of values. The random variablex(t) is the hidden state at timet (with the model from the above diagram,x(t) ∈ {x1,x2,x3}). The random variabley(t) is the observation at timet (withy(t) ∈ {y1,y2,y3,y4}). The arrows in the diagram (often called atrellis diagram) denote conditional dependencies.
From the diagram, it is clear that theconditional probability distribution of the hidden variablex(t) at timet, given the values of the hidden variablex at all times, dependsonly on the value of the hidden variablex(t − 1); the values at timet − 2 and before have no influence. This is called theMarkov property. Similarly, the value of the observed variabley(t) depends on only the value of the hidden variablex(t) (both at timet).
In the standard type of hidden Markov model considered here, the state space of the hidden variables is discrete, while the observations themselves can either be discrete (typically generated from acategorical distribution) or continuous (typically from aGaussian distribution). The parameters of a hidden Markov model are of two types,transition probabilities andemission probabilities (also known asoutput probabilities). The transition probabilities control the way the hidden state at timet is chosen given the hidden state at timet − 1.
The hidden state space is assumed to consist of one ofN possible values, modelled as a categorical distribution. (See the section below on extensions for other possibilities.) This means that for each of theN possible states that a hidden variable at timet can be in, there is a transition probability from this state to each of theN possible states of the hidden variable at timet + 1, for a total of transition probabilities. The set of transition probabilities for transitions from any given state must sum to1. Thus, theN ×N matrix of transition probabilities is aMarkov matrix. Because any transition probability can be determined once the others are known, there are a total ofN(N − 1) transition parameters.
In addition, for each of theN possible states, there is a set of emission probabilities governing the distribution of the observed variable at a particular time given the state of the hidden variable at that time. The size of this set depends on the nature of the observed variable. For example, if the observed variable is discrete withM possible values, governed by acategorical distribution, there will beM − 1 separate parameters, for a total ofN(M − 1) emission parameters over all hidden states. On the other hand, if the observed variable is anM-dimensional vector distributed according to an arbitrarymultivariate Gaussian distribution, there will beM parameters controlling themeans and parameters controlling thecovariance matrix, for a total of emission parameters. (In such a case, unless the value ofM is small, it may be more practical to restrict the nature of the covariances between individual elements of the observation vector, e.g. by assuming that the elements are independent of each other, or less restrictively, are independent of all but a fixed number of adjacent elements.)


Severalinference problems are associated with hidden Markov models, as outlined below.
The task is to compute in a best way, given the parameters of the model, the probability of a particular output sequence. This requires summation over all possible state sequences:
The probability of observing a sequence
of lengthL is given by
where the sum runs over all possible hidden-node sequences
Applying the principle ofdynamic programming, this problem, too, can be handled efficiently using theforward algorithm.
A number of related tasks ask about the probability of one or more of the latent variables, given the model's parameters and a sequence of observations.
The task is to compute, given the model's parameters and a sequence of observations, the distribution over hidden states of the last latent variable at the end of the sequence, i.e. to compute. This task is used when the sequence of latent variables is thought of as the underlying states that a process moves through at a sequence of points in time, with corresponding observations at each point. Then, it is natural to ask about the state of the process at the end.
This problem can be handled efficiently using theforward algorithm. An example is when the algorithm is applied to a Hidden Markov Network to determine.
This is similar to filtering but asks about the distribution of a latent variable somewhere in the middle of a sequence, i.e. to compute for some. From the perspective described above, this can be thought of as the probability distribution over hidden states for a point in timek in the past, relative to timet.
Theforward-backward algorithm is a good method for computing the smoothed values for all hidden state variables.
The task, unlike the previous two, asks about thejoint probability of theentire sequence of hidden states that generated a particular sequence of observations (see illustration on the right). This task is generally applicable when HMM's are applied to different sorts of problems from those for which the tasks of filtering and smoothing are applicable. An example ispart-of-speech tagging, where the hidden states represent the underlyingparts of speech corresponding to an observed sequence of words. In this case, what is of interest is the entire sequence of parts of speech, rather than simply the part of speech for a single word, as filtering or smoothing would compute.
This task requires finding a maximum over all possible state sequences, and can be solved efficiently by theViterbi algorithm.
For some of the above problems, it may also be interesting to ask aboutstatistical significance. What is the probability that a sequence drawn from somenull distribution will have an HMM probability (in the case of the forward algorithm) or a maximum state sequence probability (in the case of the Viterbi algorithm) at least as large as that of a particular output sequence?[8] When an HMM is used to evaluate the relevance of a hypothesis for a particular output sequence, the statistical significance indicates thefalse positive rate associated with failing to reject the hypothesis for the output sequence.
The parameter learning task in HMMs is to find, given an output sequence or a set of such sequences, the best set of state transition and emission probabilities. The task is usually to derive themaximum likelihood estimate of the parameters of the HMM given the set of output sequences. No tractable algorithm is known for solving this problem exactly, but a local maximum likelihood can be derived efficiently using theBaum–Welch algorithm or the Baldi–Chauvin algorithm. The Baum–Welch algorithm is a special case of theexpectation-maximization algorithm.
If the HMMs are used for time series prediction, more sophisticated Bayesian inference methods, likeMarkov chain Monte Carlo (MCMC) sampling are proven to be favorable over finding a single maximum likelihood model both in terms of accuracy and stability.[9] Since MCMC imposes significant computational burden, in cases where computational scalability is also of interest, one may alternatively resort to variational approximations to Bayesian inference, e.g.[10] Indeed, approximate variational inference offers computational efficiency comparable to expectation-maximization, while yielding an accuracy profile only slightly inferior to exact MCMC-type Bayesian inference.

HMMs can be applied in many fields where the goal is to recover a data sequence that is not immediately observable (but other data that depend on the sequence are). Applications include:
Hidden Markov models were described in a series of statistical papers byLeonard E. Baum and other authors in the second half of the 1960s.[29][30][31][32][33] One of the first applications of HMMs wasspeech recognition, starting in the mid-1970s.[34][35][36][37] From the linguistics point of view, hidden Markov models are equivalent to stochastic regular grammar.[38]
In the second half of the 1980s, HMMs began to be applied to the analysis of biological sequences,[39] in particularDNA. Since then, they have become ubiquitous in the field ofbioinformatics.[40]
In the hidden Markov models considered above, the state space of the hidden variables is discrete, while the observations themselves can either be discrete (typically generated from acategorical distribution) or continuous (typically from aGaussian distribution). Hidden Markov models can also be generalized to allow continuous state spaces. Examples of such models are those where the Markov process over hidden variables is alinear dynamical system, with a linear relationship among related variables and where all hidden and observed variables follow aGaussian distribution. In simple cases, such as the linear dynamical system just mentioned, exact inference is tractable (in this case, using theKalman filter); however, in general, exact inference in HMMs with continuous latent variables is infeasible, and approximate methods must be used, such as theextended Kalman filter or theparticle filter.
Nowadays, inference in hidden Markov models is performed innonparametric settings, where the dependency structure enablesidentifiability of the model[41] and the learnability limits are still under exploration.[42]
Hidden Markov models aregenerative models, in which thejoint distribution of observations and hidden states, or equivalently both theprior distribution of hidden states (thetransition probabilities) andconditional distribution of observations given states (theemission probabilities), is modeled. The above algorithms implicitly assume auniform prior distribution over the transition probabilities. However, it is also possible to create hidden Markov models with other types of prior distributions. An obvious candidate, given the categorical distribution of the transition probabilities, is theDirichlet distribution, which is theconjugate prior distribution of the categorical distribution. Typically, a symmetric Dirichlet distribution is chosen, reflecting ignorance about which states are inherently more likely than others. The single parameter of this distribution (termed theconcentration parameter) controls the relative density or sparseness of the resulting transition matrix. A choice of 1 yields a uniform distribution. Values greater than 1 produce a dense matrix, in which the transition probabilities between pairs of states are likely to be nearly equal. Values less than 1 result in a sparse matrix in which, for each given source state, only a small number of destination states have non-negligible transition probabilities. It is also possible to use a two-level prior Dirichlet distribution, in which one Dirichlet distribution (the upper distribution) governs the parameters of another Dirichlet distribution (the lower distribution), which in turn governs the transition probabilities. The upper distribution governs the overall distribution of states, determining how likely each state is to occur; its concentration parameter determines the density or sparseness of states. Such a two-level prior distribution, where both concentration parameters are set to produce sparse distributions, might be useful for example inunsupervisedpart-of-speech tagging, where some parts of speech occur much more commonly than others; learning algorithms that assume a uniform prior distribution generally perform poorly on this task. The parameters of models of this sort, with non-uniform prior distributions, can be learned usingGibbs sampling or extended versions of theexpectation-maximization algorithm.
An extension of the previously described hidden Markov models withDirichlet priors uses aDirichlet process in place of a Dirichlet distribution. This type of model allows for an unknown and potentially infinite number of states. It is common to use a two-level Dirichlet process, similar to the previously described model with two levels of Dirichlet distributions. Such a model is called ahierarchical Dirichlet process hidden Markov model, orHDP-HMM for short. It was originally described under the name "Infinite Hidden Markov Model"[43] and was further formalized in "Hierarchical Dirichlet Processes".[44]
A different type of extension uses adiscriminative model in place of thegenerative model of standard HMMs. This type of model directly models the conditional distribution of the hidden states given the observations, rather than modeling the joint distribution. An example of this model is the so-calledmaximum entropy Markov model (MEMM), which models the conditional distribution of the states usinglogistic regression (also known as a "maximum entropy model"). The advantage of this type of model is that arbitrary features (i.e. functions) of the observations can be modeled, allowing domain-specific knowledge of the problem at hand to be injected into the model. Models of this sort are not limited to modeling direct dependencies between a hidden state and its associated observation; rather, features of nearby observations, of combinations of the associated observation and nearby observations, or in fact of arbitrary observations at any distance from a given hidden state can be included in the process used to determine the value of a hidden state. Furthermore, there is no need for these features to bestatistically independent of each other, as would be the case if such features were used in a generative model. Finally, arbitrary features over pairs of adjacent hidden states can be used rather than simple transition probabilities. The disadvantages of such models are: (1) The types of prior distributions that can be placed on hidden states are severely limited; (2) It is not possible to predict the probability of seeing an arbitrary observation. This second limitation is often not an issue in practice, since many common usages of HMM's do not require such predictive probabilities.
A variant of the previously described discriminative model is the linear-chainconditional random field. This uses an undirected graphical model (akaMarkov random field) rather than the directed graphical models of MEMM's and similar models. The advantage of this type of model is that it does not suffer from the so-calledlabel bias problem of MEMM's, and thus may make more accurate predictions. The disadvantage is that training can be slower than for MEMM's.
Yet another variant is thefactorial hidden Markov model, which allows for a single observation to be conditioned on the corresponding hidden variables of a set of independent Markov chains, rather than a single Markov chain. It is equivalent to a single HMM, with states (assuming there are states for each chain), and therefore, learning in such a model is difficult: for a sequence of length, a straightforward Viterbi algorithm has complexity. To find an exact solution, a junction tree algorithm could be used, but it results in an complexity. In practice, approximate techniques, such as variational approaches, could be used.[45]
All of the above models can be extended to allow for more distant dependencies among hidden states, e.g. allowing for a given state to be dependent on the previous two or three states rather than a single previous state; i.e. the transition probabilities are extended to encompass sets of three or four adjacent states (or in general adjacent states). The disadvantage of such models is that dynamic-programming algorithms for training them have an running time, for adjacent states and total observations (i.e. a length- Markov chain). This extension has been widely used inbioinformatics, in the modeling ofDNA sequences.
Another recent extension is thetriplet Markov model,[46] in which an auxiliary underlying process is added to model some data specificities. Many variants of this model have been proposed. One should also mention the interesting link that has been established between thetheory of evidence and thetriplet Markov models[47] and which allows to fuse data in Markovian context[48] and to model nonstationary data.[49][50] Alternative multi-stream data fusion strategies have also been proposed in recent literature, e.g.,[51]
Finally, a different rationale towards addressing the problem of modeling nonstationary data by means of hidden Markov models was suggested in 2012.[52] It consists in employing a small recurrent neural network (RNN), specifically a reservoir network,[53] to capture the evolution of the temporal dynamics in the observed data. This information, encoded in the form of a high-dimensional vector, is used as a conditioning variable of the HMM state transition probabilities. Under such a setup, eventually is obtained a nonstationary HMM, the transition probabilities of which evolve over time in a manner that is inferred from the data, in contrast to some unrealistic ad-hoc model of temporal evolution.
In 2023, two innovative algorithms were introduced for the Hidden Markov Model. These algorithms enable the computation of the posterior distribution of the HMM without the necessity of explicitly modeling the joint distribution, utilizing only the conditional distributions.[54][55] Unlike traditional methods such as the Forward-Backward and Viterbi algorithms, which require knowledge of the joint law of the HMM and can be computationally intensive to learn, the Discriminative Forward-Backward and Discriminative Viterbi algorithms circumvent the need for the observation's law.[56][57] This breakthrough allows the HMM to be applied as a discriminative model, offering a more efficient and versatile approach to leveraging Hidden Markov Models in various applications.
The model suitable in the context of longitudinal data is named latent Markov model.[58] The basic version of this model has been extended to include individual covariates, random effects and to model more complex data structures such as multilevel data. A complete overview of the latent Markov models, with special attention to the model assumptions and to their practical use is provided in[59]

Given a Markov transition matrix and an invariant distribution on the states, a probability measure can be imposed on the set of subshifts. For example, consider the Markov chain given on the left on the states, with invariant distribution. By ignoring the distinction between, this space of subshifts is projected on into another space of subshifts on, and this projection also projects the probability measure down to a probability measure on the subshifts on.
The curious thing is that the probability measure on the subshifts on is not created by a Markov chain on, not even multiple orders. Intuitively, this is because if one observes a long sequence of, then one would become increasingly sure that the, meaning that the observable part of the system can be affected by something infinitely in the past.[60][61]
Conversely, there exists a space of subshifts on 6 symbols, projected to subshifts on 2 symbols, such that any Markov measure on the smaller subshift has a preimage measure that is not Markov of any order (example 2.6[61]).