comparison toolboxes/FullBNT-1.0.7/HMM/fixed_lag_smoother_demo.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 % Example of fixed lag smoothing
2
3 rand('state', 1);
4 S = 2;
5 O = 2;
6 T = 7;
7 data = sample_discrete([0.5 0.5], 1, T);
8 transmat = mk_stochastic(rand(S,S));
9 obsmat = mk_stochastic(rand(S,O));
10 obslik = multinomial_prob(data, obsmat);
11 prior = [0.5 0.5]';
12
13
14 [alpha0, beta0, gamma0, ll0, xi0] = fwdback(prior, transmat, obslik);
15
16 w = 3;
17 alpha1 = zeros(S, T);
18 gamma1 = zeros(S, T);
19 xi1 = zeros(S, S, T-1);
20 t = 1;
21 b = obsmat(:, data(t));
22 olik_win = b; % window of conditional observation likelihoods
23 alpha_win = normalise(prior .* b);
24 alpha1(:,t) = alpha_win;
25 for t=2:T
26 [alpha_win, olik_win, gamma_win, xi_win] = ...
27 fixed_lag_smoother(w, alpha_win, olik_win, obsmat(:, data(t)), transmat);
28 alpha1(:,max(1,t-w+1):t) = alpha_win;
29 gamma1(:,max(1,t-w+1):t) = gamma_win;
30 xi1(:,:,max(1,t-w+1):t-1) = xi_win;
31 end
32
33 e = 1e-1;
34 %assert(approxeq(alpha0, alpha1, e));
35 assert(approxeq(gamma0(:, T-w+1:end), gamma1(:, T-w+1:end), e));
36 %assert(approxeq(xi0(:,:,T-w+1:end), xi1(:,:,T-w+1:end), e));
37
38