Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/CPDs/@hhmmF_CPD/hhmmF_CPD.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 CPD = hhmmF_CPD(bnet, self, Qself, Fbelow, varargin) | |
2 % HHMMF_CPD Make the CPD for an F node in a hierarchical HMM | |
3 % CPD = hhmmF_CPD(bnet, self, Qself, Fbelow, ...) | |
4 % | |
5 % Qps | |
6 % \ | |
7 % \ | |
8 % Fself | |
9 % / | | |
10 % / | | |
11 % Qself Fbelow | |
12 % | |
13 % We assume nodes are ordered (numbered) as follows: Qps, Q, Fbelow, F | |
14 % All nodes numbers should be from slice 1. | |
15 % | |
16 % If Fbelow if missing, this becomes a regular tabular_CPD. | |
17 % Qps may be omitted. | |
18 % | |
19 % optional args [defaults] | |
20 % | |
21 % Qps - node numbers. | |
22 % termprob - termprob(k,i,2) = prob finishing given Q(d)=i and Q(1:d-1)=k [ finish in last state wp 0.9] | |
23 % | |
24 % hhmmF_CPD is a subclass of tabular_CPD so we inherit inference methods like CPD_to_pot, etc. | |
25 % | |
26 % We create an isolated tabular_CPD with no F parent to learn termprob | |
27 % so we can avail of e.g., entropic or Dirichlet priors. | |
28 % | |
29 % For details, see "Linear-time inference in hierarchical HMMs", Murphy and Paskin, NIPS'01. | |
30 | |
31 | |
32 | |
33 Qps = []; | |
34 % get parents | |
35 for i=1:2:length(varargin) | |
36 switch varargin{i}, | |
37 case 'Qps', Qps = varargin{i+1}; | |
38 end | |
39 end | |
40 | |
41 ns = bnet.node_sizes(:); | |
42 Qsz = ns(Qself); | |
43 Qpsz = prod(ns(Qps)); | |
44 CPD.Qsz = Qsz; | |
45 CPD.Qpsz = Qpsz; | |
46 | |
47 ps = parents(bnet.dag, self); | |
48 CPD.Fbelow_ndx = find_equiv_posns(Fbelow, ps); | |
49 CPD.Qps_ndx = find_equiv_posns(Qps, ps); | |
50 CPD.Qself_ndx = find_equiv_posns(Qself, ps); | |
51 | |
52 % set default arguments | |
53 p = 0.9; | |
54 %termprob(k,i,t) Might terminate if i=Qsz; will not terminate if i<Qsz | |
55 termprob = zeros(Qpsz, Qsz, 2); | |
56 termprob(:, Qsz, 2) = p; | |
57 termprob(:, Qsz, 1) = 1-p; | |
58 termprob(:, 1:(Qsz-1), 1) = 1; | |
59 | |
60 for i=1:2:length(varargin) | |
61 switch varargin{i}, | |
62 case 'termprob', termprob = varargin{i+1}; | |
63 end | |
64 end | |
65 | |
66 CPD.sub_CPD_term = mk_isolated_tabular_CPD([Qpsz Qsz 2], {'CPT', termprob}); | |
67 S = struct(CPD.sub_CPD_term); | |
68 CPD.termprob = S.CPT; | |
69 | |
70 CPD = class(CPD, 'hhmmF_CPD', tabular_CPD(bnet, self)); | |
71 | |
72 CPD = update_CPT(CPD); | |
73 |