calculation of the transition probability of a Markov's chain
5 views (last 30 days)
Show older comments
Hi all
I have to series of data (i.e. Qt and Qt+1 , in t and t+1 times, respectively). I want to calculate the transition probability of P[Qt+1 | Qt] that called first order transition probability of a Markov chain.
How can I do this.
cheers
0 Comments
Answers (1)
Walter Roberson
on 9 Mar 2012
allstates = unique([Qt(:); Qt1(:)]);
[TF, fromstate_num] = ismember(Qt, allstates);
[TF, tostate_num] = ismember(Qt1, allstates);
went_from_to_count = accumarray( [fromstate_num(:), tostate_num(:)], 1, []);
num_trans_away_from = min(1, sum(went_from_to_count, 2));
went_from_to_prob = went_from_to_count ./ repmat( num_trans_away_from, 1, size(went_from_to_count,2) );
After this,
went_from_to_prob(J,K) is P[allstates(K) | allstates(J)]
Note that an entire row could be empty, if the last state transitioned to does not otherwise occur (the "accept" state.)
0 Comments
See Also
Categories
Find more on Markov Chain Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!