Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@hmm_inf_engine/private/mk_hmm_obs_lik_vec.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 function obslik = mk_hmm_obs_lik_vec(engine, evidence) | |
2 | |
3 % P(o1,o2| h) = P(o1|h) * P(o2|h) where h = Q1,Q2,... | |
4 | |
5 bnet = bnet_from_engine(engine); | |
6 ss = length(bnet.intra); | |
7 onodes = bnet.observed; | |
8 hnodes = mysetdiff(1:ss, onodes); | |
9 ns = bnet.node_sizes(:); | |
10 ns(onodes) = 1; | |
11 | |
12 Q = length(engine.startprob); | |
13 obslik = ones(Q, 1); | |
14 | |
15 for i=1:length(onodes) | |
16 o = onodes(i); | |
17 %data = cell2num(evidence(o,1)); | |
18 data = evidence{o,1}; | |
19 if myismember(o, bnet.dnodes) | |
20 obslik_i = eval_pdf_cond_multinomial(data, engine.obsprob{i}.CPT); | |
21 else | |
22 if bnet.auto_regressive(o) | |
23 error('can''t handle AR nodes') | |
24 end | |
25 %% calling mk_ghmm_obs_lik, which calls gaussian_prob, is slow, so we inline it | |
26 %% and use the pre-computed inverse matrix | |
27 %obslik_i = mk_ghmm_obs_lik(data, engine.obsprob{i}.mu, engine.obsprob{i}.Sigma); | |
28 x = data(:); | |
29 m = engine.obsprob{i}.mu; | |
30 Qi = size(m, 2); | |
31 obslik_i = size(Qi, 1); | |
32 invC = engine.obsprob{i}.inv_Sigma; | |
33 denom = engine.obsprob{i}.denom; | |
34 for j=1:Qi | |
35 numer = exp(-0.5 * (x-m(:,j))' * invC(:,:,j) * (x-m(:,j))); | |
36 obslik_i(j) = numer / denom(j); | |
37 end | |
38 end | |
39 % convert P(o|ps) into P(o|h) by multiplying onto a (h,o) potential of all 1s | |
40 ps = bnet.parents{o}; | |
41 dom = [ps o]; | |
42 obspot_i = dpot(dom, ns(dom), obslik_i); | |
43 dom = [hnodes o]; | |
44 obspot = dpot(dom, ns(dom)); | |
45 obspot = multiply_by_pot(obspot, obspot_i); | |
46 % compute p(oi|h) * p(oj|h) | |
47 S = struct(obspot); | |
48 obslik = obslik .* S.T(:); | |
49 end | |
50 | |
51 | |
52 |