Matlab でビタビ アルゴリズムを実装しようとしていますが、i の最初のパスの後、誘導部分で何らかの理由でアルファが 0 に変わります。IE V =
0.7000 0
0.0980 0
V =
0.7000 0
0 0
V =
0.7000 0
0 0.1680
V =
0.7000 0
0 0
また、BestPath の結果は、最後に 1 を持つ一連の 0 になり、その理由はわかりません。
私のコード:
function [ViterbiScore,BestPath] = Viterbi(A,B,Pi,Obv)
%INPUTS:
%Obv = Observation sequence
%A = Transition probability matrix
%B = Emission matrix
%Pi = initial probability matrix
%OUTPUT:
%ViterbiScore
%BestPath = Best-state sequence as a vector of complex numbers.
T=length(Obv);
N=length(A(1,:));
%Initilization
for i=1:N
V(1,i)=Pi(i)*B(i,Obv(1));
BT(1,i)=0;
end
%Induction
for t=2:T
for j=1:N
for i=1:N
V(t,j)=max(V(t-1,i)*A(i,j))*B(j,Obv(t))
[rndm,BT(t,j)]=max(V(t-1,i)*A(i,j));
end
end
end
%Termination
for i=1:N
[ViterbiScore,BestPath(T)] = max(V(T,i));
end
for t=(T-1):1
BestPath(t)=BT(t+1,BestPath(t+1));
end