2

我正在尝试在 Matlab 中实现 Viterbi 算法,并且由于某种原因,在我的第一次通过后,我的归纳部分 alpha 变为 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 只会产生一堆 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
4

0 回答 0