Mercurial > hg > camir-ismir2012
annotate toolboxes/FullBNT-1.0.7/bnt/examples/limids/id1.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
rev | line source |
---|---|
Daniel@0 | 1 % influence diagram with no loops |
Daniel@0 | 2 % |
Daniel@0 | 3 % rv dec |
Daniel@0 | 4 % \ / |
Daniel@0 | 5 % utility |
Daniel@0 | 6 |
Daniel@0 | 7 N = 3; |
Daniel@0 | 8 dag = zeros(N); |
Daniel@0 | 9 X = 1; D = 2; U = 3; |
Daniel@0 | 10 dag([X D], U)=1; |
Daniel@0 | 11 |
Daniel@0 | 12 ns = zeros(1,N); |
Daniel@0 | 13 ns(X) = 2; ns(D) = 2; ns(U) = 1; |
Daniel@0 | 14 |
Daniel@0 | 15 limid = mk_limid(dag, ns, 'chance', X, 'decision', D, 'utility', U); |
Daniel@0 | 16 |
Daniel@0 | 17 % use random params |
Daniel@0 | 18 limid.CPD{X} = tabular_CPD(limid, X); |
Daniel@0 | 19 limid.CPD{D} = tabular_decision_node(limid, D); |
Daniel@0 | 20 limid.CPD{U} = tabular_utility_node(limid, U); |
Daniel@0 | 21 |
Daniel@0 | 22 %fname = '/home/cs/murphyk/matlab/Misc/loopybel.txt'; |
Daniel@0 | 23 global BNT_HOME |
Daniel@0 | 24 fname = sprintf('%s/loopybel.txt', BNT_HOME); |
Daniel@0 | 25 |
Daniel@0 | 26 engines = {}; |
Daniel@0 | 27 engines{end+1} = global_joint_inf_engine(limid); |
Daniel@0 | 28 engines{end+1} = jtree_limid_inf_engine(limid); |
Daniel@0 | 29 %engines{end+1} = belprop_inf_engine(limid, 'max_iter', 2*N, 'filename', fname); |
Daniel@0 | 30 engines{end+1} = belprop_inf_engine(limid, 'max_iter', 2*N); |
Daniel@0 | 31 |
Daniel@0 | 32 exact = [1 2]; |
Daniel@0 | 33 approx = 3; |
Daniel@0 | 34 |
Daniel@0 | 35 E = length(engines); |
Daniel@0 | 36 strategy = cell(1, E); |
Daniel@0 | 37 MEU = zeros(1, E); |
Daniel@0 | 38 for e=1:E |
Daniel@0 | 39 [strategy{e}, MEU(e)] = solve_limid(engines{e}); |
Daniel@0 | 40 MEU |
Daniel@0 | 41 end |
Daniel@0 | 42 MEU |
Daniel@0 | 43 |
Daniel@0 | 44 for e=exact(:)' |
Daniel@0 | 45 assert(approxeq(strategy{exact(1)}{D}, strategy{e}{D})) |
Daniel@0 | 46 end |
Daniel@0 | 47 |
Daniel@0 | 48 for e=approx(:)' |
Daniel@0 | 49 approxeq(strategy{exact(1)}{D}, strategy{e}{D}) |
Daniel@0 | 50 end |