wolffd@0: % decision theoretic version of asia network wolffd@0: % Cowell et al, p177 wolffd@0: % We explicitely add the no-forgetting arcs. wolffd@0: wolffd@0: Smoking = 1; wolffd@0: VisitToAsia = 2; wolffd@0: Bronchitis = 3; wolffd@0: LungCancer = 4; wolffd@0: TB = 5; wolffd@0: Do_Xray = 6; wolffd@0: TBorCancer = 7; wolffd@0: Util_Xray = 8; wolffd@0: Dys = 9; wolffd@0: posXray = 10; wolffd@0: Do_Hosp = 11; wolffd@0: Util_Hosp = 12; wolffd@0: wolffd@0: n = 12; wolffd@0: dag = zeros(n); wolffd@0: dag(Smoking, [Bronchitis LungCancer]) = 1; wolffd@0: dag(VisitToAsia, [TB Do_Xray Do_Hosp]) = 1; wolffd@0: dag(Bronchitis, Dys) = 1; wolffd@0: dag(LungCancer, [Util_Hosp TBorCancer]) = 1; wolffd@0: dag(TB, [Util_Hosp TBorCancer Util_Xray]) = 1; wolffd@0: dag(Do_Xray, [posXray Util_Xray Do_Hosp]) = 1; wolffd@0: dag(TBorCancer, [Dys posXray]) = 1; wolffd@0: dag(Dys, Do_Hosp) = 1; wolffd@0: dag(posXray, Do_Hosp) = 1; wolffd@0: dag(Do_Hosp, Util_Hosp) = 1; wolffd@0: wolffd@0: dnodes = [Do_Xray Do_Hosp]; wolffd@0: unodes = [Util_Xray Util_Hosp]; wolffd@0: cnodes = mysetdiff(1:n, [dnodes unodes]); % chance nodes wolffd@0: ns = 2*ones(1,n); wolffd@0: ns(unodes) = 1; wolffd@0: limid = mk_limid(dag, ns, 'chance', cnodes, 'decision', dnodes, 'utility', unodes); wolffd@0: wolffd@0: % 1 = yes, 2 = no wolffd@0: limid.CPD{VisitToAsia} = tabular_CPD(limid, VisitToAsia, [0.01 0.99]); wolffd@0: limid.CPD{Bronchitis} = tabular_CPD(limid, Bronchitis, [0.6 0.3 0.4 0.7]); wolffd@0: 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: limid.CPD{TBorCancer} = tabular_CPD(limid, TBorCancer, [1 1 1 0 0 0 0 1]); wolffd@0: wolffd@0: limid.CPD{LungCancer} = tabular_CPD(limid, LungCancer, [0.1 0.01 0.9 0.99]); wolffd@0: limid.CPD{Smoking} = tabular_CPD(limid, Smoking, [0.5 0.5]); wolffd@0: limid.CPD{TB} = tabular_CPD(limid, TB, [0.05 0.01 0.95 0.99]); wolffd@0: 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: wolffd@0: limid.CPD{Util_Hosp} = tabular_utility_node(limid, Util_Hosp, [180 120 160 15 2 4 0 40]); wolffd@0: limid.CPD{Util_Xray} = tabular_utility_node(limid, Util_Xray, [0 1 10 10]); wolffd@0: wolffd@0: for i=dnodes(:)' wolffd@0: limid.CPD{i} = tabular_decision_node(limid, i); wolffd@0: end wolffd@0: wolffd@0: engines = {}; wolffd@0: engines{end+1} = global_joint_inf_engine(limid); wolffd@0: engines{end+1} = jtree_limid_inf_engine(limid); wolffd@0: %engines{end+1} = belprop_inf_engine(limid); wolffd@0: wolffd@0: exact = [1 2]; wolffd@0: %approx = 3; wolffd@0: approx = []; wolffd@0: wolffd@0: wolffd@0: NE = length(engines); wolffd@0: MEU = zeros(1, NE); wolffd@0: niter = zeros(1, NE); wolffd@0: strategy = cell(1, NE); wolffd@0: wolffd@0: tol = 1e-2; wolffd@0: for e=1:length(engines) wolffd@0: [strategy{e}, MEU(e), niter(e)] = solve_limid(engines{e}); wolffd@0: end wolffd@0: wolffd@0: for e=exact(:)' wolffd@0: assert(approxeq(MEU(e), 47.49, tol)) wolffd@0: assert(isequal(strategy{e}{Do_Xray}(:)', [1 0 0 1])) wolffd@0: wolffd@0: % Check the hosptialize strategy is correct (p180) wolffd@0: % We assume the patient has not been to Asia and therefore did not have an Xray. wolffd@0: % In this case it is optimal not to hospitalize regardless of whether the patient has wolffd@0: % dyspnoea or not (and of course regardless of the value of pos_xray). wolffd@0: asia = 2; wolffd@0: do_xray = 2; wolffd@0: for dys = 1:2 wolffd@0: for pos_xray = 1:2 wolffd@0: assert(argmax(squeeze(strategy{e}{Do_Hosp}(asia, do_xray, dys, pos_xray, :))) == 2) wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: for e=approx(:)' wolffd@0: approxeq(strategy{exact(1)}{Do_Xray}, strategy{e}{Do_Xray}) wolffd@0: approxeq(strategy{exact(1)}{Do_Hosp}, strategy{e}{Do_Hosp}) wolffd@0: end wolffd@0: wolffd@0: wolffd@0: