wolffd@0: % Compare various inference engines on the following network (from Jensen (1996) p84 fig 4.17) wolffd@0: % 1 wolffd@0: % / | \ wolffd@0: % 2 3 4 wolffd@0: % | | | wolffd@0: % 5 6 7 wolffd@0: % \/ \/ wolffd@0: % 8 9 wolffd@0: % where all arcs point downwards wolffd@0: wolffd@0: N = 9; wolffd@0: dag = zeros(N,N); wolffd@0: dag(1,2)=1; dag(1,3)=1; dag(1,4)=1; wolffd@0: dag(2,5)=1; dag(3,6)=1; dag(4,7)=1; wolffd@0: dag(5,8)=1; dag(6,8)=1; dag(6,9)=1; dag(7,9) = 1; wolffd@0: wolffd@0: dnodes = 1:N; wolffd@0: false = 1; true = 2; wolffd@0: ns = 2*ones(1,N); % binary nodes wolffd@0: wolffd@0: onodes = [1]; wolffd@0: evidence = cell(1,N); wolffd@0: evidence(onodes) = num2cell(1); wolffd@0: bnet = mk_bnet(dag, ns, 'observed', onodes); wolffd@0: % use random params wolffd@0: %for i=1:N wolffd@0: % bnet.CPD{i} = tabular_CPD(bnet, i); wolffd@0: %end wolffd@0: bnet.CPD{1} = tabular_CPD(bnet, 1, 'sparse', 1, 'CPT', [0.8, 0.2]); wolffd@0: bnet.CPD{2} = tabular_CPD(bnet, 2, 'sparse', 1, 'CPT', [1 0 0 1]); wolffd@0: bnet.CPD{3} = tabular_CPD(bnet, 3, 'sparse', 1, 'CPT', [0 1 1 0]); wolffd@0: bnet.CPD{4} = tabular_CPD(bnet, 4, 'sparse', 1, 'CPT', [1 1 0 0]); wolffd@0: bnet.CPD{5} = tabular_CPD(bnet, 5, 'sparse', 1, 'CPT', [0 0 1 1]); wolffd@0: bnet.CPD{6} = tabular_CPD(bnet, 6, 'sparse', 1, 'CPT', [1 0 0 1]); wolffd@0: bnet.CPD{7} = tabular_CPD(bnet, 7, 'sparse', 1, 'CPT', [0 1 1 0]); wolffd@0: bnet.CPD{8} = tabular_CPD(bnet, 8, 'sparse', 1, 'CPT', [1 1 0 0 0 0 1 1]); wolffd@0: bnet.CPD{9} = tabular_CPD(bnet, 9, 'sparse', 1, 'CPT', [0 1 0 1 1 0 1 0]); wolffd@0: wolffd@0: engine = jtree_sparse_inf_engine(bnet); wolffd@0: tic wolffd@0: [engine, ll] = enter_evidence(engine, evidence); wolffd@0: toc wolffd@0: