필터 지우기
필터 지우기

how to programme to calculate transition probability matrix?

조회 수: 8 (최근 30일)
Ram k
Ram k 2016년 5월 5일
편집: Patrick Laux 2018년 11월 10일
Suppose I have a sequence of states like 1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1. Transition probability matrix calculated by following equation probability=(number of pairs x(t) followed by x(t+1))/(number of pairs x(t) followed by any state). transition probability matrix calculated by manually by me as follows
1 3 2 4 5
1 0 1/5 2/5 2/5 0
3 3/4 1/4 0 0 0
2 1/4 1/4 0 1/4 1/4
4 0 1/5 2/5 2/5 0
5 1 0 0 0 0
how to programme to obtain above transition probability matrix.

답변 (1개)

James Tursa
James Tursa 2016년 5월 5일
편집: James Tursa 2016년 5월 5일
E.g., brute force:
m = max(x);
n = numel(x);
y = zeros(m,1);
p = zeros(m,m);
for k=1:n-1
y(x(k)) = y(x(k)) + 1;
p(x(k),x(k+1)) = p(x(k),x(k+1)) + 1;
end
p = bsxfun(@rdivide,p,y); p(isnan(p)) = 0;
The p matrix will be ordered by natural indexing. E.g., 1, 2, 3, 4, 5 for the above example. It will not be ordered as 1, 3, 2, 4, 5 as you have it above. I.e., the probability of going from state i to state j is p(i,j).
  댓글 수: 4
Ram k
Ram k 2016년 5월 7일
편집: Ram k 2016년 5월 7일
I have a sequence in which states may not be start from 1 and also may not have subsequent numbers i.e. some numbers may be absent so sequence like this 12,14,6,15,15,15,15,6,8,8,18,18,14,14 so I want build transition probability matrix and it should be like below
6 8 12 14 15 18
6 0 1/2 0 0 1/2 0
8 0 1/2 0 0 0 1/2
12 0 0 0 1 0 0
14 1/2 0 0 1/2 0 0
15 1/4 0 0 0 3/4 0
18 0 0 0 0 1/2 1/2
I tried by above programme but matrix forms from number 1 to max number of state i.e. 18, so finally matrix becomes 18*18 order but i want matrix like above because states which are not present corresponding position becomes 0 and matrix becomes very large. In matrix redundancy occurs at places because of 0, so how to built matrix like above posted by me.
Patrick Laux
Patrick Laux 2018년 11월 10일
편집: Patrick Laux 2018년 11월 10일
The brute force code above is giving 5 if you sum up all probabilities ??
Shouldn't it be: p = bsxfun(@rdivide,p,n) ?
However, this, i.e. sum(sum(p)) also gives only 0.95 (not 1). I am confused now.
Maybe: p = bsxfun(@rdivide,p,n-1) ??

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Markov Chain Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by