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