comparison toolboxes/FullBNT-1.0.7/bnt/CPDs/@hhmm2Q_CPD/CPD_to_CPT.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 CPT = CPD_to_CPT(CPD)
2 % Compute the big CPT for an HHMM Q node (including F parents)
3 % by combining internal transprob and startprob
4 % function CPT = CPD_to_CPT(CPD)
5
6 Qsz = CPD.Qsz;
7
8 if ~isempty(CPD.Fbelow_ndx)
9 if ~isempty(CPD.Fself_ndx) % general case
10 error('not implemented')
11 else % no F from self, hence no startprob (top level)
12 nps = length(CPD.dom_sz)-1; % num parents
13 CPT = 0*myones(CPD.dom_sz);
14 % when Fself=1, the CPT(i,j) = delta(i,j) for all k
15 for k=1:prod(CPD.Qpsizes)
16 Qps_vals = ind2subv(CPD.Qpsizes, k);
17 ndx = mk_multi_index(nps+1, [CPD.Fbelow_ndx CPD.Qps_ndx], [1 Qps_vals]);
18 CPT(ndx{:}) = eye(Qsz); % CPT(:,2,k,:) or CPT(:,k,2,:) etc
19 end
20 ndx = mk_multi_index(nps+1, CPD.Fbelow_ndx, 2);
21 CPT(ndx{:}) = CPD.transprob; % we assume transprob is in topo order
22 end
23 else % no F signal from below
24 if ~isempty(CPD.Fself_ndx) % bottom level
25 nps = length(CPD.dom_sz)-1; % num parents
26 CPT = 0*myones(CPD.dom_sz);
27 ndx = mk_multi_index(nps+1, CPD.Fself_ndx, 1);
28 CPT(ndx{:}) = CPD.transprob;
29 ndx = mk_multi_index(nps+1, CPD.Fself_ndx, 2);
30 CPT(ndx{:}) = CPD.startprob;
31 else % no F from self
32 error('An hhmmQ node without any F parents is just a tabular_CPD')
33 end
34 end
35