Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/examples/limids/id1.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 % influence diagram with no loops |
wolffd@0 | 2 % |
wolffd@0 | 3 % rv dec |
wolffd@0 | 4 % \ / |
wolffd@0 | 5 % utility |
wolffd@0 | 6 |
wolffd@0 | 7 N = 3; |
wolffd@0 | 8 dag = zeros(N); |
wolffd@0 | 9 X = 1; D = 2; U = 3; |
wolffd@0 | 10 dag([X D], U)=1; |
wolffd@0 | 11 |
wolffd@0 | 12 ns = zeros(1,N); |
wolffd@0 | 13 ns(X) = 2; ns(D) = 2; ns(U) = 1; |
wolffd@0 | 14 |
wolffd@0 | 15 limid = mk_limid(dag, ns, 'chance', X, 'decision', D, 'utility', U); |
wolffd@0 | 16 |
wolffd@0 | 17 % use random params |
wolffd@0 | 18 limid.CPD{X} = tabular_CPD(limid, X); |
wolffd@0 | 19 limid.CPD{D} = tabular_decision_node(limid, D); |
wolffd@0 | 20 limid.CPD{U} = tabular_utility_node(limid, U); |
wolffd@0 | 21 |
wolffd@0 | 22 %fname = '/home/cs/murphyk/matlab/Misc/loopybel.txt'; |
wolffd@0 | 23 global BNT_HOME |
wolffd@0 | 24 fname = sprintf('%s/loopybel.txt', BNT_HOME); |
wolffd@0 | 25 |
wolffd@0 | 26 engines = {}; |
wolffd@0 | 27 engines{end+1} = global_joint_inf_engine(limid); |
wolffd@0 | 28 engines{end+1} = jtree_limid_inf_engine(limid); |
wolffd@0 | 29 %engines{end+1} = belprop_inf_engine(limid, 'max_iter', 2*N, 'filename', fname); |
wolffd@0 | 30 engines{end+1} = belprop_inf_engine(limid, 'max_iter', 2*N); |
wolffd@0 | 31 |
wolffd@0 | 32 exact = [1 2]; |
wolffd@0 | 33 approx = 3; |
wolffd@0 | 34 |
wolffd@0 | 35 E = length(engines); |
wolffd@0 | 36 strategy = cell(1, E); |
wolffd@0 | 37 MEU = zeros(1, E); |
wolffd@0 | 38 for e=1:E |
wolffd@0 | 39 [strategy{e}, MEU(e)] = solve_limid(engines{e}); |
wolffd@0 | 40 MEU |
wolffd@0 | 41 end |
wolffd@0 | 42 MEU |
wolffd@0 | 43 |
wolffd@0 | 44 for e=exact(:)' |
wolffd@0 | 45 assert(approxeq(strategy{exact(1)}{D}, strategy{e}{D})) |
wolffd@0 | 46 end |
wolffd@0 | 47 |
wolffd@0 | 48 for e=approx(:)' |
wolffd@0 | 49 approxeq(strategy{exact(1)}{D}, strategy{e}{D}) |
wolffd@0 | 50 end |