Calculating probability matrices of a table for a discrete time Markov chain
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Siddharth Solanki
2021-7-13
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Markov Chain Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!