wolffd@0
|
1 % decision theoretic version of asia network
|
wolffd@0
|
2 % Cowell et al, p177
|
wolffd@0
|
3 % We explicitely add the no-forgetting arcs.
|
wolffd@0
|
4
|
wolffd@0
|
5 Smoking = 1;
|
wolffd@0
|
6 VisitToAsia = 2;
|
wolffd@0
|
7 Bronchitis = 3;
|
wolffd@0
|
8 LungCancer = 4;
|
wolffd@0
|
9 TB = 5;
|
wolffd@0
|
10 Do_Xray = 6;
|
wolffd@0
|
11 TBorCancer = 7;
|
wolffd@0
|
12 Util_Xray = 8;
|
wolffd@0
|
13 Dys = 9;
|
wolffd@0
|
14 posXray = 10;
|
wolffd@0
|
15 Do_Hosp = 11;
|
wolffd@0
|
16 Util_Hosp = 12;
|
wolffd@0
|
17
|
wolffd@0
|
18 n = 12;
|
wolffd@0
|
19 dag = zeros(n);
|
wolffd@0
|
20 dag(Smoking, [Bronchitis LungCancer]) = 1;
|
wolffd@0
|
21 dag(VisitToAsia, [TB Do_Xray Do_Hosp]) = 1;
|
wolffd@0
|
22 dag(Bronchitis, Dys) = 1;
|
wolffd@0
|
23 dag(LungCancer, [Util_Hosp TBorCancer]) = 1;
|
wolffd@0
|
24 dag(TB, [Util_Hosp TBorCancer Util_Xray]) = 1;
|
wolffd@0
|
25 dag(Do_Xray, [posXray Util_Xray Do_Hosp]) = 1;
|
wolffd@0
|
26 dag(TBorCancer, [Dys posXray]) = 1;
|
wolffd@0
|
27 dag(Dys, Do_Hosp) = 1;
|
wolffd@0
|
28 dag(posXray, Do_Hosp) = 1;
|
wolffd@0
|
29 dag(Do_Hosp, Util_Hosp) = 1;
|
wolffd@0
|
30
|
wolffd@0
|
31 dnodes = [Do_Xray Do_Hosp];
|
wolffd@0
|
32 unodes = [Util_Xray Util_Hosp];
|
wolffd@0
|
33 cnodes = mysetdiff(1:n, [dnodes unodes]); % chance nodes
|
wolffd@0
|
34 ns = 2*ones(1,n);
|
wolffd@0
|
35 ns(unodes) = 1;
|
wolffd@0
|
36 limid = mk_limid(dag, ns, 'chance', cnodes, 'decision', dnodes, 'utility', unodes);
|
wolffd@0
|
37
|
wolffd@0
|
38 % 1 = yes, 2 = no
|
wolffd@0
|
39 limid.CPD{VisitToAsia} = tabular_CPD(limid, VisitToAsia, [0.01 0.99]);
|
wolffd@0
|
40 limid.CPD{Bronchitis} = tabular_CPD(limid, Bronchitis, [0.6 0.3 0.4 0.7]);
|
wolffd@0
|
41 limid.CPD{Dys} = tabular_CPD(limid, Dys, [0.9 0.7 0.8 0.1 0.1 0.3 0.2 0.9]);
|
wolffd@0
|
42 limid.CPD{TBorCancer} = tabular_CPD(limid, TBorCancer, [1 1 1 0 0 0 0 1]);
|
wolffd@0
|
43
|
wolffd@0
|
44 limid.CPD{LungCancer} = tabular_CPD(limid, LungCancer, [0.1 0.01 0.9 0.99]);
|
wolffd@0
|
45 limid.CPD{Smoking} = tabular_CPD(limid, Smoking, [0.5 0.5]);
|
wolffd@0
|
46 limid.CPD{TB} = tabular_CPD(limid, TB, [0.05 0.01 0.95 0.99]);
|
wolffd@0
|
47 limid.CPD{posXray} = tabular_CPD(limid, posXray, [0.98 0.5 0.05 0.5 0.02 0.5 0.95 0.5]);
|
wolffd@0
|
48
|
wolffd@0
|
49 limid.CPD{Util_Hosp} = tabular_utility_node(limid, Util_Hosp, [180 120 160 15 2 4 0 40]);
|
wolffd@0
|
50 limid.CPD{Util_Xray} = tabular_utility_node(limid, Util_Xray, [0 1 10 10]);
|
wolffd@0
|
51
|
wolffd@0
|
52 for i=dnodes(:)'
|
wolffd@0
|
53 limid.CPD{i} = tabular_decision_node(limid, i);
|
wolffd@0
|
54 end
|
wolffd@0
|
55
|
wolffd@0
|
56 engines = {};
|
wolffd@0
|
57 engines{end+1} = global_joint_inf_engine(limid);
|
wolffd@0
|
58 engines{end+1} = jtree_limid_inf_engine(limid);
|
wolffd@0
|
59 %engines{end+1} = belprop_inf_engine(limid);
|
wolffd@0
|
60
|
wolffd@0
|
61 exact = [1 2];
|
wolffd@0
|
62 %approx = 3;
|
wolffd@0
|
63 approx = [];
|
wolffd@0
|
64
|
wolffd@0
|
65
|
wolffd@0
|
66 NE = length(engines);
|
wolffd@0
|
67 MEU = zeros(1, NE);
|
wolffd@0
|
68 niter = zeros(1, NE);
|
wolffd@0
|
69 strategy = cell(1, NE);
|
wolffd@0
|
70
|
wolffd@0
|
71 tol = 1e-2;
|
wolffd@0
|
72 for e=1:length(engines)
|
wolffd@0
|
73 [strategy{e}, MEU(e), niter(e)] = solve_limid(engines{e});
|
wolffd@0
|
74 end
|
wolffd@0
|
75
|
wolffd@0
|
76 for e=exact(:)'
|
wolffd@0
|
77 assert(approxeq(MEU(e), 47.49, tol))
|
wolffd@0
|
78 assert(isequal(strategy{e}{Do_Xray}(:)', [1 0 0 1]))
|
wolffd@0
|
79
|
wolffd@0
|
80 % Check the hosptialize strategy is correct (p180)
|
wolffd@0
|
81 % We assume the patient has not been to Asia and therefore did not have an Xray.
|
wolffd@0
|
82 % In this case it is optimal not to hospitalize regardless of whether the patient has
|
wolffd@0
|
83 % dyspnoea or not (and of course regardless of the value of pos_xray).
|
wolffd@0
|
84 asia = 2;
|
wolffd@0
|
85 do_xray = 2;
|
wolffd@0
|
86 for dys = 1:2
|
wolffd@0
|
87 for pos_xray = 1:2
|
wolffd@0
|
88 assert(argmax(squeeze(strategy{e}{Do_Hosp}(asia, do_xray, dys, pos_xray, :))) == 2)
|
wolffd@0
|
89 end
|
wolffd@0
|
90 end
|
wolffd@0
|
91 end
|
wolffd@0
|
92
|
wolffd@0
|
93
|
wolffd@0
|
94 for e=approx(:)'
|
wolffd@0
|
95 approxeq(strategy{exact(1)}{Do_Xray}, strategy{e}{Do_Xray})
|
wolffd@0
|
96 approxeq(strategy{exact(1)}{Do_Hosp}, strategy{e}{Do_Hosp})
|
wolffd@0
|
97 end
|
wolffd@0
|
98
|
wolffd@0
|
99
|
wolffd@0
|
100
|