Hidden Markov model in MATLAB

I have 11 states and a transition probability matrix, but I have no outliers, since my model is not hidden. It consists only of states (1,2,3, ..., 11)
I want to generate random states based on my transition probability matrix, but the radiation probability matrix is ​​required for the HMM window. What should I do?

[seq, states] = hmmgenerate(100, Trans, Emis) 
+5
source share
1 answer

Consider the following:

%# number of states
N = 11;

%# some random transition matrix
trans = rand(N,N);
trans = bsxfun(@rdivide, trans, sum(trans,2));

%# fake emission matrix (only one symbol)
emis = ones(N,1);

%# get a sample of length = 10
[~,states] = hmmgenerate(10, trans, emis)

The sequence of generated states:

>> states
states =
    10     1     3    11     9     4    11     1     4     6

EDIT:

In fact, working with the Markov chain is relatively simple, we can do it ourselves. Here is another example without using the HMM functions from the statistics toolbar.

%# number of states
N = 3;

%# transition matrix
trans = rand(N,N);
trans = bsxfun(@rdivide, trans, sum(trans,2));

%# probability of being in state i at time t=0
prior = rand(1,N);
prior = prior ./ sum(prior);

%# generate a sequence of states
len = 100;          %# length of sequence
states = zeros(1,len);
states(1) = randsample(N, 1, true, prior);
for t=2:len
    states(t) = randsample(N, 1, true, trans(states(t-1),:));
end

%# show sequence
stairs(states, 'LineWidth',2)
set(gca, 'YGrid','on', 'YLim',[0 N+1])
xlabel('time'), ylabel('states')
title('sequence of states')

sequence of states

RANDSAMPLE . ( ), . MATLAB .

+6

All Articles