annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/discrete2.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 % Compare various inference engines on the following network (from Jensen (1996) p84 fig 4.17)
wolffd@0 2 % 1
wolffd@0 3 % / | \
wolffd@0 4 % 2 3 4
wolffd@0 5 % | | |
wolffd@0 6 % 5 6 7
wolffd@0 7 % \/ \/
wolffd@0 8 % 8 9
wolffd@0 9 % where all arcs point downwards
wolffd@0 10 seed = 0;
wolffd@0 11 rand('state', seed);
wolffd@0 12 randn('state', seed);
wolffd@0 13
wolffd@0 14 N = 9;
wolffd@0 15 dag = zeros(N,N);
wolffd@0 16 dag(1,2)=1; dag(1,3)=1; dag(1,4)=1;
wolffd@0 17 dag(2,5)=1; dag(3,6)=1; dag(4,7)=1;
wolffd@0 18 dag(5,8)=1; dag(6,8)=1; dag(6,9)=1; dag(7,9) = 1;
wolffd@0 19
wolffd@0 20 dnodes = 1:N;
wolffd@0 21 false = 1; true = 2;
wolffd@0 22 ns = 2*ones(1,N); % binary nodes
wolffd@0 23
wolffd@0 24 onodes = [2 4];
wolffd@0 25 bnet = mk_bnet(dag, ns, 'observed', onodes);
wolffd@0 26 % use random params
wolffd@0 27 for i=1:N
wolffd@0 28 bnet.CPD{i} = tabular_CPD(bnet, i);
wolffd@0 29 end
wolffd@0 30
wolffd@0 31 %USEC = exist('@jtree_C_inf_engine/collect_evidence','file');
wolffd@0 32 query = [3];
wolffd@0 33 engine = {};
wolffd@0 34 engine{end+1} = jtree_inf_engine(bnet);
wolffd@0 35 engine{end+1} = jtree_sparse_inf_engine(bnet);
wolffd@0 36 %engine{end+1} = jtree_ndx_inf_engine(bnet, 'ndx_type', 'SD');
wolffd@0 37 %engine{end+1} = jtree_ndx_inf_engine(bnet, 'ndx_type', 'B');
wolffd@0 38 %engine{end+1} = jtree_ndx_inf_engine(bnet, 'ndx_type', 'D');
wolffd@0 39 %if USEC, engine{end+1} = jtree_C_inf_engine(bnet); end
wolffd@0 40 %engine{end+1} = var_elim_inf_engine(bnet);
wolffd@0 41 %engine{end+1} = enumerative_inf_engine(bnet);
wolffd@0 42 %engine{end+1} = jtree_onepass_inf_engine(bnet, query, onodes);
wolffd@0 43
wolffd@0 44 maximize = 0; % jtree_ndx crashes on max-prop
wolffd@0 45 [err, time] = cmp_inference_static(bnet, engine, 'maximize', maximize);
wolffd@0 46