资源简介
隐马尔科夫模型HMM的具体算法代码,包括前向、后向算法、EM参数重估等。
代码片段和文件信息
function [Lp q_dec]=hmm_vitdecg(a pi mu var o)
%--------------------------------------------------------------------------
%Viterbi decoder (with gaussian observations)
% [Lpq] = hmm_vitdecd(apipoo)
%
% inputs:
% a(ij) transition probability matrix a(ij) :=p(q_t=j|q_t-1=i)
% pi(i) initial probability pi(i) :=p(q_1=i )
% mu(i) mean of gaussian probability at state i
% var(i) variance of gaussian probability at state i
% o observation sequence
%
% outputs:
% Lp log probability of optimal path
% q_dec optimal state sequence
%--------------------------------------------------------------------------
% See also HMM_DECD
% $Revision: 1.0 $ $Date: 2008/10/04 00:00:00 $
%% check inputs
% number of states
N=size(a1);
if N~=size(a2)
fprintf(1‘error state transition probability matrix should be square\n‘);
return;
end
% length of observation
T=length(o);
%% viterbi algorithm for state estimation
Ld=zeros(NT);
f=zeros(NT);
coff=-log(3.141592653589793)/2; % const
% init
Lb= coff-log(var)-0.5*(o(1)-mu).^2./var;
Ld(:1)=log(pi)+Lb;
f(:1)=0;
% interation
for t=2:T
for j=1:N
dd=Ld(:t-1)+log(a(:j)); % log probability of path from state 1~N to state j
[mx idx]=max(dd); % find optimal path to state j
f(jt)=idx; % record the optimal path to j @ time t
o_t=o(t);
mu_j=mu(j);
var_j=var(j);
Lb_j=coff-log(var_j)-0.5*(o_t-mu_j)^2/var_j; % log probability of output o_t given current state j
Ld(jt)=mx + Lb_j; % log probability of optimal path to j with output o_t
end
end
[mx idx]=max(Ld(:T));
Lp=mx; % log probability of optimal path
q_last=idx; % optimal last state
%% arrange result
q_dec=zeros(1T);
for t=T:-1:1
q_dec(t)=q_last;
q_last=f(q_lastt);
end
return;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1999 2009-03-11 17:23 hmm\.m
文件 316767 2009-03-11 17:27 hmm\EM算法与HMM参数估计20081003.pdf
文件 1329 2009-03-11 17:22 hmm\hmm_backward.m
文件 2216 2011-11-30 12:24 hmm\hmm_bw.m
文件 1331 2011-11-14 17:58 hmm\hmm_forward.m
文件 2177 2011-11-14 10:36 hmm\hmm_vitdecd.asv
文件 2179 2011-11-14 17:07 hmm\hmm_vitdecd.m
文件 1999 2009-03-11 17:23 hmm\hmm_vitdecg.m
文件 711 2009-03-11 17:24 hmm\log_add.m
文件 558 2009-03-11 17:24 hmm\log_sum.m
文件 253 2009-03-11 17:24 hmm\randdist.m
文件 1693 2011-11-14 17:56 hmm\test_hmm_bw.m
文件 1423 2011-11-14 11:05 hmm\Test_hmm_forward_backword.m
文件 413 2009-03-11 17:25 hmm\test_hmm_vitdecd.m
文件 1040 2009-03-11 17:26 hmm\test_hmm_vitdecd_long.m
文件 1384 2009-03-11 17:25 hmm\test_hmm_vitdecg_long.m
目录 0 2011-11-14 10:36 hmm
----------- --------- ---------- ----- ----
337472 17
- 上一篇:ELM回归预测matlab版code
- 下一篇:计算互信息的matlab程序
评论
共有 条评论