Skip to content

Commit

Permalink
add recursive hmm smoother
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Sep 12, 2016
1 parent f1ca9ba commit 90d4783
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chapter13/HMM/hmmRecSmoother_.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function [ gamma, c ] = hmmRecSmoother_( M, A, s )
% Forward-backward (recursive gamma no alpha-beta) alogrithm for HMM to compute posterior p(z_i|x)
% Input:
% x: 1xn observation
% s: kx1 starting probability of p(z_1|s)
% A: kxk transition probability
% E: kxd emission probability
% Output:
% gamma: 1xn posterier p(z_i|x)
% llh: loglikelihood or evidence lnp(x)
% Written by Mo Chen [email protected]
[K,T] = size(M);
At = A';
c = zeros(1,T); % normalization constant
gamma = zeros(K,T);
[gamma(:,1),c(1)] = nml(s.*M(:,1),1);
for t = 2:T
[gamma(:,t),c(t)] = nml((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);
end

0 comments on commit 90d4783

Please sign in to comment.