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