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