Skip to content

Commit

Permalink
fix a hmmRecSmoother
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Sep 12, 2016
1 parent 90d4783 commit ad6c784
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions chapter13/HMM/hmmRecSmoother_.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
At = A';
c = zeros(1,T); % normalization constant
gamma = zeros(K,T);
[gamma(:,1),c(1)] = nml(s.*M(:,1),1);
[gamma(:,1),c(1)] = normalize(s.*M(:,1),1);
for t = 2:T
[gamma(:,t),c(t)] = nml((At*gamma(:,t-1)).*M(:,t),1); % 13.59
[gamma(:,t),c(t)] = normalize((At*gamma(:,t-1)).*M(:,t),1); % 13.59
end
for t = T-1:-1:1
gamma(:,t) = nml(bsxfun(@times,A,gamma(:,t)),1)*gamma(:,t+1);
gamma(:,t) = normalize(bsxfun(@times,A,gamma(:,t)),1)*gamma(:,t+1);
end

6 changes: 4 additions & 2 deletions chapter13/HMM/hmmSmoother.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function [gamma, alpha, beta, c] = hmmSmoother(x, model)
% HMM smoothing alogrithm (normalized forward-backward or normalized alpha-beta algorithm). This is a wrapper function which transform input and call underlying algorithm
% Unlike the method described in the book of PRML, the alpha returned is the normalized version: gamma(t)=p(z_t|x_{1:T})
% Computing unnormalized version gamma(t)=p(z_t,x_{1:T}) is numerical unstable, which grows exponential fast to infinity.
% Unlike the method described in the book of PRML, the alpha and beta
% returned is the normalized.
% Computing unnormalized version alpha and beta is numerical unstable, which grows exponential fast to infinity.
% Input:
% x: 1 x n integer vector which is the sequence of observations
% model: model structure
Expand All @@ -20,3 +21,4 @@
X = sparse(x,1:n,1,d,n);
M = E*X;
[gamma, alpha, beta, c] = hmmSmoother_(M, A, s);
% [gamma,c] = hmmRecSmoother_(M, A, s);
5 changes: 3 additions & 2 deletions chapter13/HMM/hmmSmoother_.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function [gamma, alpha, beta, c] = hmmSmoother_(M, A, s)
% Implmentation function HMM smoothing alogrithm.
% Unlike the method described in the book of PRML, the alpha returned is the normalized version: gamma(t)=p(z_t|x_{1:T})
% Computing unnormalized version gamma(t)=p(z_t,x_{1:T}) is numerical unstable, which grows exponential fast to infinity.
% Unlike the method described in the book of PRML, the alpha and beta
% returned is the normalized.
% Computing unnormalized version alpha and beta is numerical unstable, which grows exponential fast to infinity.
% Input:
% M: k x n emmision data matrix M=E*X
% A: k x k transition matrix
Expand Down

0 comments on commit ad6c784

Please sign in to comment.