Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/limids/oil1.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 % oil wildcatter influence diagram in Cowell et al p172 | |
2 | |
3 % T = test for oil? | |
4 % UT = utility (negative cost) of testing | |
5 % O = amount of oil = Dry, Wet or Soaking | |
6 % R = results of test = NoStrucure, OpenStructure, ClosedStructure or NoResult | |
7 % D = drill? | |
8 % UD = utility of drilling | |
9 | |
10 % Decision sequence = T R D O | |
11 | |
12 T = 1; UT = 2; O = 3; R = 4; D = 5; UD = 6; | |
13 N = 6; | |
14 dag = zeros(N); | |
15 dag(T, [UT R D]) = 1; | |
16 dag(O, [R UD]) = 1; | |
17 dag(R, D) = 1; | |
18 dag(D, UD) = 1; | |
19 | |
20 ns = zeros(1,N); | |
21 ns(O) = 3; ns(R) = 4; ns(T) = 2; ns(D) = 2; ns(UT) = 1; ns(UD) = 1; | |
22 | |
23 limid = mk_limid(dag, ns, 'chance', [O R], 'decision', [T D], 'utility', [UT UD]); | |
24 | |
25 limid.CPD{O} = tabular_CPD(limid, O, [0.5 0.3 0.2]); | |
26 tbl = [0.6 0 0.3 0 0.1 0 0.3 0 0.4 0 0.4 0 0.1 0 0.3 0 0.5 0 0 1 0 1 0 1]; | |
27 limid.CPD{R} = tabular_CPD(limid, R, tbl); | |
28 | |
29 limid.CPD{UT} = tabular_utility_node(limid, UT, [-10 0]); | |
30 limid.CPD{UD} = tabular_utility_node(limid, UD, [-70 50 200 0 0 0]); | |
31 | |
32 if 1 | |
33 % start with uniform policies | |
34 limid.CPD{T} = tabular_decision_node(limid, T); | |
35 limid.CPD{D} = tabular_decision_node(limid, D); | |
36 else | |
37 % hard code optimal policies | |
38 limid.CPD{T} = tabular_decision_node(limid, T, [1.0 0.0]); | |
39 a = 0.5; b = 1-a; % arbitrary value | |
40 tbl = myreshape([0 a 1 a 1 a a a 1 b 0 b 0 b b b], ns([T R D])); | |
41 limid.CPD{D} = tabular_decision_node(limid, D, tbl); | |
42 end | |
43 | |
44 %fname = '/home/cs/murphyk/matlab/Misc/loopybel.txt'; | |
45 | |
46 engines = {}; | |
47 engines{end+1} = global_joint_inf_engine(limid); | |
48 engines{end+1} = jtree_limid_inf_engine(limid); | |
49 %engines{end+1} = belprop_inf_engine(limid, 'max_iter', 3*N, 'filename', fname); | |
50 | |
51 exact = [1 2]; | |
52 %approx = 3; | |
53 approx = []; | |
54 | |
55 E = length(engines); | |
56 strategy = cell(1, E); | |
57 MEU = zeros(1, E); | |
58 for e=1:E | |
59 [strategy{e}, MEU(e)] = solve_limid(engines{e}); | |
60 MEU | |
61 end | |
62 MEU | |
63 | |
64 for e=exact(:)' | |
65 assert(approxeq(MEU(e), 22.5)) | |
66 % U(T=yes) U(T=no) | |
67 % 1 0 | |
68 assert(argmax(strategy{e}{T}) == 1); % test = yes | |
69 t = 1; % test = yes | |
70 % strategy{D} T R U(D=yes=1) U(D=no=2) | |
71 % 1=yes 1=noS 0 1 Don't drill | |
72 % 2=no 1=noS 1 0 | |
73 % 1=yes 2=opS 1 0 | |
74 % 2=no 2=opS 1 0 | |
75 % 1=yes 3=clS 1 0 | |
76 % 2=no 3=clS 1 0 | |
77 % 1=yes 4=unk 1 0 | |
78 % 2=no 4=unk 1 0 | |
79 | |
80 for r=[2 3] % OpS, ClS | |
81 assert(argmax(squeeze(strategy{e}{D}(t,r,:))) == 1); % drill = yes | |
82 end | |
83 r = 1; % noS | |
84 assert(argmax(squeeze(strategy{e}{D}(t,r,:))) == 2); % drill = no | |
85 end | |
86 | |
87 | |
88 for e=approx(:)' | |
89 approxeq(strategy{exact(1)}{T}, strategy{e}{T}) | |
90 approxeq(strategy{exact(1)}{D}, strategy{e}{D}) | |
91 end |