To explain the format of the "seq" and "states" parameters of the HMMESTIMATE function, a hidden Markov model will be used.
First, take a non-fair coin, with a probability "p" of coming up heads. The two states shall be defined as "heads" and "tails", and the transition from one state to the next is defined by the next flip of the coin. Therefore, the transition matrix would be:
Assume that whenever the coin is in state 1, the value of the model is 2, and whenever the coin is in state 2, the value of the model is 1 or 3, with equal probability. Therefore, the emission matrix will be:
E = [0 1 0; ...
1/2 0 1/2];
If you simulate the hidden Markov model states using the TM matrix (choosing a state at random each simulation step based on the probabilities given in TM), and record the state of the model at each simulation step, the "states" parameter for HMMESTIMATE is obtained. Likewise, if you take that "states" parameter and generate a random value for the model at each simulation step (using the probabilities from the E matrix), the vector of sequence values "seq" is obtained.
To clarify, if the coin is twice as likely to come up heads as tails, you would expect "states" to have twice as many 1's as 2's. You would also expect that the "seq" vector will be one-fourth 1, one-half 2, and one-fourth 3:
p = 2/3;
TM = [p 1-p; ...
p 1-p];
E = [0 1 0; ...
1/2 0 1/2];
[SEQ, STATES] = hmmgenerate(1000, TM, E);
[TM_est, E_est] = hmmestimate(SEQ, STATES)
Best Answer