Calculating probability matrices of a table for a discrete time Markov chain
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Wells
am 12 Jul. 2021
Kommentiert: Michael Wells
am 13 Jul. 2021
Hello, I need help creating the probability matrices for a discrete time Markov chain from a table. The table is (5448x144) where the 144 columns correspond to 10 min intervals.
My data in each cell is one of three states (value in the cell ranges from 1-3), I am trying to create a probability matirx P for each time interval to express the probability that the state will transistion to a new state or remain the same.
How can I check the probability of a state changing from one column to the next using MatLab functions, and loop this for each column? I have given a small example of the table below:
For example the section below would have the probability matrix in transition from wher_28 to wher_29 as follows;
P=[0.875 0.000 0.125;
1.000 0.000 0.000;
0.000 0.000 1.000;]
Thanks,
Michael
0 Kommentare
Akzeptierte Antwort
Siddharth Solanki
am 13 Jul. 2021
The below code calculates the 143 required transition probability matrices. In the code below I have used matrix ‘data’ as the input. You may refer this link for converting a table to matrix.
data = randi([1,3],[5448,144]); %Matrix representing data
transition_matrices = zeros([3,3,143]); %Initializing all the 143 transition prob matrices
for c=1:143
for r=1:5448
%Updating the probability matix based on this column and next
%column's values
% 1 2 3 (Next Column)
%(This col) 1
% 2
% 3
% Each cell is a transition probability value
dim1val = data(r,c);
dim2val = data(r,c+1);
transition_matrices(dim1val,dim2val,c)= transition_matrices(dim1val,dim2val,c)+1;
end
%Normalizing the summed values to find probability
transition_matrices(:,:,c)= transition_matrices(:,:,c)/5448;
end
Additionally you can vectorize the code if required.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Markov Chain Models finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!