Two state markov chain realization
Mostrar comentarios más antiguos
I have a state transition probability matrix and a state probability vector
[0.9 0.1; 0.1 0.9] & [0.4 0.6] respectively.
Now, I want to generate the states according to this. say 100 state sequence.
Any sort of help would be appreciated.
Thanks.
Respuesta aceptada
Más respuestas (1)
Fangjun Jiang
el 2 de Jul. de 2011
0 votos
You've asked the same question multiple times. Sounds like you need to go back to your textbook to learn what is state transition probability and Markov chain.
5 comentarios
lemontree45
el 2 de Jul. de 2011
Fangjun Jiang
el 2 de Jul. de 2011
Your code looks good. And I apologize for the mistake that I made in my answer to your previous question. p=p/100 is incorrect. Should do like you did. p(1,1)=p(1,1)/s1 stuff.
Now let's debug your code. First I think you need to set an initial state. Because, s1+s2=100, there are 100 transitions. In your current code, there are 99 transitions. In your current code, before doing p(1,1)=p(1,1)/s1 stuff, you can check that sum(sum(p)) equals 99, which will later cause you probability matrix problem. Each row of the probability matrix should sum equals 1. Make sure you check that before doing the reversing.
Fangjun Jiang
el 2 de Jul. de 2011
You don't have to do the same as mine. Your code can achieve the same. But the important thing at the end of calculation p (or P in my case) is to make sure
>> sum(P,2)
ans =
1
1
Here is my code.
N=100;
Data=rand(N,1);
TF=Data>0.5;
Data(TF)=2;
Data(~TF)=1;
P=zeros(2,2);
FromState=1;
for k=1:N
ToState=Data(k);
P(FromState,ToState)=P(FromState,ToState)+1;
FromState=ToState;
end
P(2,:)=P(2,:)/sum(TF);
P(1,:)=P(1,:)/sum(~TF);
lemontree45
el 2 de Jul. de 2011
Fangjun Jiang
el 2 de Jul. de 2011
I don't think you can re-generate the exact sequence. Think about your probability matrix, it is derived from 100 state transition. There are so many other slightly varied sequence that can draw to the same probability matrix.
When you generate the state probability vector, remember that you vector should be defined as row vector as V=[0.9 0.1], and the next vector would be V*P. This is different from cyclist because the definition of P(1,1), P(1,2),P(2,1),P(2,2).
Categorías
Más información sobre Descriptive Statistics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!