Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/hhmm_jtree_clqs.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 % Find out how big the cliques are in an HHMM as a function of depth | |
2 % (This is how we get the complexity bound of O(D K^{1.5D}).) | |
3 | |
4 if 0 | |
5 Qsize = []; | |
6 Fsize = []; | |
7 Nclqs = []; | |
8 end | |
9 | |
10 ds = 1:15; | |
11 | |
12 for d = ds | |
13 allQ = 1; | |
14 [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(d, allQ); | |
15 | |
16 N = length(intra); | |
17 ns = 2*ones(1,N); | |
18 | |
19 bnet = mk_dbn(intra, inter, ns); | |
20 for i=1:N | |
21 bnet.CPD{i} = tabular_CPD(bnet, i); | |
22 end | |
23 | |
24 if 0 | |
25 T = 5; | |
26 dag = unroll_dbn_topology(intra, inter, T); | |
27 engine = jtree_unrolled_dbn_inf_engine(bnet, T, 'constrained', 1); | |
28 S = struct(engine); | |
29 S1 = struct(S.sub_engine); | |
30 end | |
31 | |
32 engine = jtree_dbn_inf_engine(bnet); | |
33 S = struct(engine); | |
34 J = S.jtree_struct; | |
35 | |
36 ss = 2*d+1; | |
37 Qnodes2 = Qnodes + ss; | |
38 QQnodes = [Qnodes Qnodes2]; | |
39 | |
40 % find out how many Q nodes in each clique, and how many F nodes | |
41 C = length(J.cliques); | |
42 Nclqs(d) = 0; | |
43 for c=1:C | |
44 Qsize(c,d) = length(myintersect(J.cliques{c}, QQnodes)); | |
45 Fsize(c,d) = length(myintersect(J.cliques{c}, Fnodes)); | |
46 if length(J.cliques{c}) > 1 % exclude observed leaves | |
47 Nclqs(d) = Nclqs(d) + 1; | |
48 end | |
49 end | |
50 %pred_max_Qsize(d) = ceil(d+(d+1)/2); | |
51 pred_max_Qsize(d) = ceil(1.5*d); | |
52 | |
53 fprintf('d=%d\n', d); | |
54 %fprintf('D=%d, max F = %d. max Q = %d, pred max Q = %d\n', ... | |
55 % D, max(Fsize), max(Qsize), ceil(D+(D+1)/2)); | |
56 | |
57 %histc(Qsize,1:max(Qsize)) % how many of each size? | |
58 end % next d | |
59 | |
60 | |
61 Q = 2; | |
62 pred_mass = ds.*(Q.^ds) + Q.^(ceil(1.5 * ds)) | |
63 pred_mass2 = Q.^(ceil(1.5 * ds)) | |
64 | |
65 for d=ds | |
66 mass(d) = 0; | |
67 for c=1:C | |
68 mass(d) = mass(d) + Q^Qsize(c,d); | |
69 end | |
70 end | |
71 | |
72 | |
73 if 0 | |
74 %plot(ds, max(Qsize), 'o-', ds, pred_max_Qsize, '*--'); | |
75 %plot(ds, max(Qsize), 'o-', ds, 1.5*ds, '*--'); | |
76 %plot(ds, mass, 'o-', ds, pred_mass, '*--'); | |
77 D = 15; | |
78 %plot(ds(1:D), mass(1:D), 'bo-', ds(1:D), pred_mass(1:D), 'g*--', ds(1:D), pred_mass2(1:D), 'k+-.'); | |
79 plot(ds(1:D), log(mass(1:D)), 'bo-', ds(1:D), log(pred_mass(1:D)), 'g*--', ds(1:D), log(pred_mass2(1:D)), 'k+-.'); | |
80 | |
81 grid on | |
82 xlabel('depth of hierarchy') | |
83 title('max num Q nodes in any clique vs. depth') | |
84 legend('actual', 'predicted') | |
85 | |
86 %previewfig(gcf, 'width', 3, 'height', 1.5, 'color', 'bw'); | |
87 %exportfig(gcf, '/home/cs/murphyk/WP/ConferencePapers/HHMM/clqsize2.eps', ... | |
88 % 'width', 3, 'height', 1.5, 'color', 'bw'); | |
89 | |
90 end | |
91 | |
92 | |
93 if 0 | |
94 for d=ds | |
95 effnumclqs(d) = length(find(Qsize(:,d)>0)); | |
96 end | |
97 ds = 1:10; | |
98 Qs = 2:10; | |
99 maxC = size(Qsize, 1); | |
100 cost = []; | |
101 cost_bound = []; | |
102 for qi=1:length(Qs) | |
103 Q = Qs(qi); | |
104 for d=ds | |
105 cost(d,qi) = 0; | |
106 for c=1:maxC | |
107 if length(Qsize(c,d) > 0) % this clique contains Q nodes | |
108 cost(d,qi) = cost(d,qi) + Q^Qsize(c,d)*2^Fsize(c,d); | |
109 end | |
110 end | |
111 %cost_bound(d,qi) = effnumclqs(d) * 8 * Q^(max(Qsize(:,d))); | |
112 cost_bound(d,qi) = (effnumclqs(d)*8) + Q^(max(Qsize(:,d))); | |
113 end | |
114 end | |
115 | |
116 qi=2; plot(ds, cost(:,qi), 'o-', ds, cost_bound(:,qi), '*--'); | |
117 end | |
118 | |
119 | |
120 if 0 | |
121 % convert numbers in cliques into names | |
122 for d=1:D | |
123 Fdecode(Fnodes(d)) = d; | |
124 end | |
125 for c=8:15 | |
126 clqs = J.cliques{c}; | |
127 fprintf('clique %d: ', c); | |
128 for k=clqs | |
129 if myismember(k, Qnodes) | |
130 fprintf('Q%d ', k) | |
131 elseif myismember(k, Fnodes) | |
132 fprintf('F%d ', Fdecode(k)) | |
133 elseif isequal(k, Onode) | |
134 fprintf('O ') | |
135 elseif myismember(k, Qnodes2) | |
136 fprintf('Q%d* ', k-ss) | |
137 else | |
138 error(['unrecognized node ' k]) | |
139 end | |
140 end | |
141 fprintf('\n'); | |
142 end | |
143 end |