forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|