Why State Count Is a Predictive Choice
A hidden Markov model with more states can represent more patterns in a sequence, but added flexibility can also fit accidental features of the training data. The number of states is therefore not chosen by asking only which model achieves the largest likelihood on the data used to fit it. For a prediction-focused comparison, fit each candidate model on training sequences, then evaluate how well it assigns probability to separate held-out sequences.
Let \((\Omega,\mathcal{F},\mathbb{P})\) be a probability space. In a candidate model with \(K\) hidden states, the hidden process \((X_t)_{t\ge1}\) has state space \(S=\{1,\ldots,K\}\) and discrete time \(t=1,\ldots,T\). The observations \((Y_t)_{t\ge1}\) take values in an alphabet \(\mathcal{A}\). The initial hidden-state distribution is the row vector \(\pi\); the transition matrix is \(P=(p_{ij})\), with nonnegative entries and each row summing to \(1\). In state \(i\), an observation \(y\) has probability \(b_i(y)\), where \(\sum_{y\in\mathcal{A}}b_i(y)=1\). Given the hidden states, observations are conditionally independent, with \(Y_t\) distributed according to \(b_{X_t}\).
Each likelihood sums over all possible hidden-state paths; it does not select one path and score only that path. The forward recursion is a convenient way to do this calculation. Define \(\alpha_t(i)=\mathbb{P}_\theta(Y_1=y_1,\ldots,Y_t=y_t,X_t=i)\). Then
Proof. At \(t=1\), the event \(X_1=i\) has probability \(\pi_i\), and, conditional on that state, \(Y_1=y_1\) has probability \(b_i(y_1)\). Multiplication gives the stated \(\alpha_1(i)\). For \(t\ge2\), the event counted by \(\alpha_t(j)\) can be partitioned into the disjoint possibilities \(X_{t-1}=i\), for \(i=1,\ldots,K\). For each such possibility, the joint probability of the observations through time \(t-1\) and the transition to \(j\) is \(\alpha_{t-1}(i)p_{ij}\). The probability of the new observation given \(X_t=j\) is \(b_j(y_t)\). Summing over \(i\) and multiplying by this emission probability gives the recursion. Finally, the events \(X_T=i\) partition the sample event \(Y_{1:T}=y_{1:T}\), so summing \(\alpha_T(i)\) over \(i\) gives its probability. \(\square\)
Split at the Prediction Unit
If the goal is to predict a new independent sequence, split the data by whole sequences before fitting the candidate models. Fit each state-count candidate using the training sequences only, and evaluate its sequence likelihood on the held-out sequences. When multiple sequences come from the same person, household, or other sampling unit, the split should generally keep that unit together if the target is prediction for a new unit. Otherwise, information specific to a unit can appear on both sides of the split.
The split should match the intended prediction task. For forecasting later observations from a sequence whose earlier observations are already available, a chronological split can be appropriate: the earlier prefix supplies the prediction context, and the later segment is scored. That is a different task from predicting a wholly new sequence. Randomly scattering observations from the same trajectory between training and held-out data does not evaluate either task cleanly.
For candidate state counts \(K\) in a specified set, let \(\widehat{\theta}_K\) denote the parameter fitted using training data. A prediction-based choice is
This criterion compares the probabilities assigned to the same held-out sequences. A larger score means a larger likelihood for those sequences under the fitted candidate; it does not establish that the model is true or that it will win on every future sample. If several state counts tie, preferring the smaller one is a transparent parsimony rule, not a consequence of the likelihood calculation.
Worked Example: Identical Transition Rows Do Not Preserve a Hidden State
Consider two candidate models for binary observations \(0\) and \(1\), and held-out sequences \(111\) and \(000\). The one-state model has transition matrix \(P=(1)\), initial probability \(1\), and emission probabilities \(b(1)=b(0)=\tfrac12\). The two-state model has initial distribution \((\tfrac12,\tfrac12)\), transition matrix
Each row of the two-state transition matrix sums to \(\tfrac12+\tfrac12=1\), and the one-state row sums to \(1\). In the two-state model, the hidden state is freshly distributed as \((\tfrac12,\tfrac12)\) at every time: each transition row is that same distribution. Therefore, at each time the marginal probability of \(1\) is \(\tfrac12\cdot\tfrac9{10}+\tfrac12\cdot\tfrac1{10}=\tfrac12\), and the marginal probability of \(0\) is \(\tfrac12\cdot\tfrac1{10}+\tfrac12\cdot\tfrac9{10}=\tfrac12\). The emissions at different times are independent in this model because the hidden states are independently redrawn and the emissions are conditionally independent. Thus
The two held-out sequences are independent sampling units, so their joint likelihood is \(\tfrac18\cdot\tfrac18=\tfrac1{64}\). The one-state model gives the same calculation: each of its three observations has probability \(\tfrac12\), so each sequence has likelihood \(\tfrac18\), and the pair has likelihood \(\tfrac1{64}\). The held-out scores tie. This calculation also checks the forward recursion: in the two-state model, after each observation the summed forward mass is multiplied by \(\tfrac12\), giving \((\tfrac12)^3\) for either sequence.
Predictive Fit and Training Fit Are Different
The training log likelihood measures how well a fitted model accounts for data used in fitting. Its value is useful for diagnosing optimization and comparing models under appropriate conditions, but it is not an independent assessment of prediction. The distinction can be stated precisely for nested model classes.
Proof. Every parameter \(\theta\in\Theta_1\) also belongs to \(\Theta_2\), so \(L(\theta;D)\le\sup_{\vartheta\in\Theta_2}L(\vartheta;D)\) for every \(\theta\in\Theta_1\). Taking the supremum of the left side over \(\Theta_1\) preserves the inequality and proves the likelihood statement. If maxima exist, both suprema are attained. Likelihoods are nonnegative, and the logarithm is increasing on positive numbers; taking logs therefore preserves the ordering when the maxima are positive. If a maximum likelihood is zero, its log score is \(-\infty\), and the same ordering holds in the extended real numbers. \(\square\)
This result applies only when one parameter class really contains the other. A model with more hidden states is not automatically a nested enlargement for every choice of emission and transition restrictions. Even when nesting holds, the proposition concerns training likelihood only; it says nothing about held-out likelihood. Flexible models can assign larger likelihood to the data they were fitted on without assigning larger probability to new sequences.
Worked Example: A Persistent Two-State Model on Held-Out Sequences
Use the same one-state candidate as above, which assigns probability \(\tfrac12\) to each binary symbol. Compare it with a two-state model having initial distribution \((\tfrac12,\tfrac12)\), transition matrix
Each transition row sums to \(\tfrac9{10}+\tfrac1{10}=1\); each state's two emission probabilities also sum to \(1\). Score the two independent held-out sequences \(111\) and \(000\). For \(111\), the forward values after the first observation are \(\alpha_1(1)=\tfrac12\cdot\tfrac9{10}=\tfrac9{20}\) and \(\alpha_1(2)=\tfrac12\cdot\tfrac1{10}=\tfrac1{20}\). At time \(2\),
and
At time \(3\),
while
Hence \(L(111)=\tfrac{2997}{10000}+\tfrac{45}{10000}=\tfrac{3042}{10000}=\tfrac{1521}{5000}\). Interchanging the two hidden-state labels and the two emission symbols leaves this model unchanged, so the same forward calculation with the labels interchanged gives \(L(000)=\tfrac{1521}{5000}\). The pair likelihood is therefore \((\tfrac{1521}{5000})^2=\tfrac{2313441}{25000000}\). For the one-state model, the pair likelihood is \((\tfrac18)^2=\tfrac1{64}\). Since \(\tfrac{1521}{5000}>\tfrac18\), as verified by \(8\cdot1521=12168>5000\), the two-state candidate has the higher held-out score on this particular pair. This is an evaluation of these specified candidates and sequences, not a guarantee about other held-out data.
Choose the Score That Matches the Goal
The pooled held-out log likelihood gives each observation its contribution to the joint sequence likelihood. Dividing by the total number of observations reports an average log score per observation, without changing the ranking when all candidates are evaluated on the same sequences. If the scientific target instead weights each independent sequence equally, one may report an average of within-sequence log scores, with an explicit decision about whether to divide each sequence's score by its length. These summaries answer different questions when lengths vary; state the chosen summary before comparing candidates.
Worked Example: Pooled and Equal-Sequence Scores Can Rank Differently
Consider two one-state binary models: model A has probability \(\tfrac34\) for \(1\) and \(\tfrac14\) for \(0\); model B has probability \(\tfrac12\) for either symbol. Each model's one-state transition matrix is \(P=(1)\), whose row sums to \(1\), and each model's emission probabilities sum to \(1\). Evaluate sequences \(111\) and \(0\). Their lengths are \(3\) and \(1\).
For the pooled score, model A assigns likelihood \((\tfrac34)^3=\tfrac{27}{64}\) to \(111\), and \(\tfrac14\) to \(0\). The joint likelihood is \(\tfrac{27}{64}\cdot\tfrac14=\tfrac{27}{256}\). Model B assigns \((\tfrac12)^3=\tfrac18\) to \(111\) and \(\tfrac12\) to \(0\), for joint likelihood \(\tfrac1{16}\). Because \(\tfrac{27}{256}>\tfrac{16}{256}=\tfrac1{16}\), model A wins by pooled log likelihood. Its per-observation score is \(\tfrac14\log(\tfrac{27}{256})\), whereas model B's is \(\tfrac14\log(\tfrac1{16})\), so the per-observation ranking is also A over B.
Now give each sequence equal weight after dividing its log likelihood by its own length. For model A, the per-observation log scores of the two sequences are \(\log(\tfrac34)\) and \(\log(\tfrac14)\); their average is \(\tfrac12\log(\tfrac3{16})=\log(\tfrac{\sqrt{3}}4)\). For model B, both per-observation scores equal \(\log(\tfrac12)\), so their average is \(\log(\tfrac12)\). Since \(\sqrt{3}<2\), we have \(\tfrac{\sqrt{3}}4<\tfrac12\), and the equal-sequence average favors model B. The rankings differ because this score gives the short sequence as much weight as the long one. Neither summary is universally correct; choose according to the prediction target.
Common Pitfalls and a Practical Comparison
A common error is to treat the initial hidden-state mixture as if one state were selected once and then held fixed for the entire sequence. In the identical-row example, that mistaken calculation gives \(L(111)=\tfrac12(\tfrac9{10})^3+\tfrac12(\tfrac1{10})^3=\tfrac{730}{2000}=\tfrac{73}{200}\). It is wrong because the transition matrix redraws the state at every step, rather than preserving the initial state. The correct calculation is \((\tfrac12\cdot\tfrac9{10}+\tfrac12\cdot\tfrac1{10})^3=(\tfrac12)^3=\tfrac18\). Always use the transition probabilities at each time, or apply the forward recursion, when summing over paths.
For a defensible state-count comparison, keep the held-out sequences fixed across candidates, fit parameters without using those sequences, compute each sequence likelihood with the full HMM likelihood rather than a decoded path, and report the score definition and length handling. The in-sample likelihood may rise with model flexibility, especially for nested classes, while held-out scores can favor a smaller candidate. A validation comparison is itself noisy, particularly with few independent sequences; the selected state count is evidence about predictive performance under the chosen split and scoring rule, not a universal property of the data.
Check Your Understanding
Answer each question using the definitions and calculations above.
- For an HMM, what does \(\alpha_t(i)\) represent, and why does summing \(\alpha_T(i)\) over states give the sequence likelihood?
- If every row of a transition matrix is the same distribution, what does that imply about the hidden state at successive times?
- Why should whole independent sequences be assigned to training or held-out data when the goal is prediction for a new sequence?
- What condition on two parameter classes is needed to guarantee that the larger class has at least as high a maximized in-sample likelihood?
- In the unequal-length example, why do pooled per-observation and equal-sequence scores rank the candidates differently?