How to create a Markov chain sequence given the transition matrix and the states

3 Ansichten (letzte 30 Tage)
There is 5 states as follows:
QS=[2.0243
-0.6361
0.7770
1.0486
1.1569] % or QS={2.024 ,-0.6361 ,0.7770, 1.0486 ,1.1569}
And this is the transition matrix that has the probabilities of going from one state to another:
P=[0.5000 0.0556 0.0556 0.0556 0.0556
0.0556 0.5000 0.0556 0.0556 0.0556
0.0556 0.0556 0.5000 0.0556 0.0556
0.0556 0.0556 0.0556 0.5000 0.0556
0.0556 0.0556 0.0556 0.0556 0.5000];
How can I get a Markov chain sequence Js=[Js(1)...Js(t)] from these given P and QS? (t is a given time)
I used the following code to produce the sequence but it does not use the state space which is known in computing the sequence.
transition_probabilities=P;
chain_length=512;
chain = zeros(1,chain_length);
chain(1)=starting_value; %Starting value=1;
for i=2:chain_length
this_step_distribution = transition_probabilities(chain(i-1),:);
cumulative_distribution = cumsum(this_step_distribution);
r = rand();
chain(i) = find(cumulative_distribution>r,1);
end
Will I still get the right sequence, even if I don't use the State space?

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by