this code is not working for transition probability matrix ....make it correct?

1 次查看(过去 30 天)
my transition probability matrix equation is given under link. http://latex.codecogs.com/gif.latex?p1_{h}(i,j)=\frac{\sum_{u=1}^{S_{u}-2}\sum_{v=1}^{S_{v}}\delta%20(F_{h}(u,v)=i,{F_{h}}(u+1,v)=j)}{\sum_{u=1}^{^{S_{u}-2}}%20\sum_{v=1}^{^{S_{v}}}\delta%20({F_{h}(u,v)=i})}
for this eqn i wrote code given below
sv=128;
su=128;
for i=1:9
for j=1:9
a(i,j)=0;
for u=1:su-2
for v=1:sv
if (Yh(u,v)==i && Yh(u+1,v)==j)
dell=1;
else
dell=0;
end
a(i,j)=a(i,j)+dell;
b(i,j)=0;
if(Yh(u,v)==i)
dell1=1;
else
dell1=0;
end
b(i,j)=b(i,j)+dell1;
end
end
end
end
.....the final result want to know for above code is p=a./b.... and here the dell value as considered as dell(.)=1 if and only if its argumens are satisfied, otherwise dell(.)=0.
  2 个评论
Dhines
Dhines 2013-1-17
please check it ..this is another eqn<http://latex.codecogs.com/gif.latex?P1v(i,j)=\frac{{\sum_{u=1}^{^{S_{u}-1}}\sum_{v=1}^{S_{v}-1}\delta%20({F_{h}(u,v)=i,{F_{h}(u,v+1)=j}})}}{\sum_{u=1}^{{S_{u}-1}}\sum_{v=1}^{S_{v}-1}\delta%20(F_{h}(u,v)=i)}>..... i wrote code for this eqn is p1v=zeros(9); for ii=1:9 p1=Yh(1:end-1,:)==ii; for jj=1:9 p2=Yh(:,2:end-1)==jj; p1v(ii,jj) = nnz(p1 & p2)./nnz(p1); end end ...is it correct ?
Jan
Jan 2013-1-17
What does "is not working" mean? Do you get an error message or do the results differ from your expectations?

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2013-1-11
Why are you setting b(i,j)=0 inside each "for v" iteration ?

Andrei Bobrov
Andrei Bobrov 2013-1-11
编辑:Andrei Bobrov 2013-1-11
p1h = zeros(9);
for ii = 1:9
p1 = Yh(1:end-2,:) == ii;
for jj = 1:9
p2 = Yh(2:end-1,:) == jj;
p1h(ii,jj) = nnz(p1 & p2)./nnz(p1);
end
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by