필터 지우기
필터 지우기

Transition Matrix -ve states and sum not 1, or 1 with negative probablities

조회 수: 1 (최근 30일)
Masood Abbasi
Masood Abbasi 2018년 4월 30일
편집: Masood Abbasi 2018년 4월 30일
I have implemented following equation in Matalb
This equation is for calculating transition Matrix Probabilities (Pi,i+j) of this Markov Chain
The code i have written is as follows, where Nt=2:
for i=0:Nt % sum over all i's
for d=0:Nt %sum over all d's
for d1=0:min(i,d) %sum for all possible d1's
for a=0:d %sum for all a's
%index=sprintf("Index i=%d j=%d i=%d i+j=%d \n",i,d1-a, i,i+d1-a)
for k=a:d
if (i==0 || d1==i)
p=pf;
else
p=pa;
end
A= nchoosek(d,k) * (PSI^k) *( (1-PSI)^(d-k) )* nchoosek(k,a) *(p^a)*(1-p)^(k-a);
if( Nt-i > d-d1)
%A= nchoosek(d,k) * PSI *( (1-PSI)^(d-k) )* nchoosek(k,a) *(p^a)*(1-p)^(k-a);
M=nchoosek(i,d1)* nchoosek(Nt-i,d-d1) *(Pi1^d)* (1-Pi1)^(Nt-d) * A ;
end
%make transition matrix array
%newIndex=sprintf("Index i=%d j=%d i=%d i+j=%d \n",i,d1-a, i,i+d1-a)
%values=sprintf("Index i=%d d=%d d1=%d a=%d ,k=%d j=%d i=%d i+j=%d \n",i,d,d1,a,k,d1-a, i,i+d1-a)
if ( (i+d1-a) > 0 && (i+d1-a <= Nt)) %( (i<=Nt) && (i+d1-a <=Nt) && (i+d1-a >=0) )
% newIndex=sprintf("Index i=%d j=%d i=%d i+j=%d \n",i,d1-a, i,i+d1-a);
TM(i+1,i+d1-a+1)=TM(i+1,i+d1-a+1)+M; % for indexing +1
end
end
end
end
end
end
Following are observations from this equation 1) I get negative index sometimes eg. for i+j i.e. Pi,i+j =P0,-1 we dont have '-1' as state. 2) The transition Matrix sums to 1 for about 75% rows. When i ran this code with Nt=40. i was getting sum of rows=1 for 35 rows only. With Nt=10, first row becomes all 0's and 4 rows have sum equal to '1'. 3) In some cases sum of Rows element =1 when having negative probabilities like 1.234 -0.234 0.0 = 1
Can any expert tell me if i have mistakes in code or else.
Thank you

답변 (0개)

카테고리

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