annotate toolboxes/FullBNT-1.0.7/bnt/examples/limids/amnio.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1
wolffd@0 2 clear all
wolffd@0 3 B0 = 1; Rtriple = 2; Damnio = 3;
wolffd@0 4 B1 = 4; Ramnio = 5; Dabort = 6;
wolffd@0 5 B2 = 7; U = 8;
wolffd@0 6
wolffd@0 7 N = 8;
wolffd@0 8 dag = zeros(N,N);
wolffd@0 9 dag(B0, [Rtriple B1 Ramnio]) = 1;
wolffd@0 10 dag(Rtriple, [Damnio Dabort]) = 1;
wolffd@0 11 dag(Damnio, [B1 Ramnio]) = 1;
wolffd@0 12 dag(B1, B2) = 1;
wolffd@0 13 dag(Ramnio, [Dabort U]) = 1;
wolffd@0 14 dag(Dabort, B2) = 1;
wolffd@0 15 dag(B2, U) = 1;
wolffd@0 16
wolffd@0 17
wolffd@0 18
wolffd@0 19 ns = zeros(1,N);
wolffd@0 20 ns(B0) = 2;
wolffd@0 21 ns(B1) = 3;
wolffd@0 22 ns(B2) = 4;
wolffd@0 23 ns(Rtriple) = 2;
wolffd@0 24 ns(Ramnio) = 3;
wolffd@0 25 ns(Damnio) = 2;
wolffd@0 26 ns(Dabort) = 2;
wolffd@0 27 ns(U) = 1;
wolffd@0 28
wolffd@0 29 limid = mk_limid(dag, ns, 'chance', [B0 B1 B2], ...
wolffd@0 30 'decision', [Damnio Dabort], 'utility', [U]);
wolffd@0 31
wolffd@0 32 % states of nature
wolffd@0 33 healthy = 1; downs = 2; miscarry = 3; aborted = 4;
wolffd@0 34 % test results
wolffd@0 35 pos = 1; neg = 2; unk = 3;
wolffd@0 36 % actions
wolffd@0 37 yes = 1; no = 2;
wolffd@0 38
wolffd@0 39 % Prior probability baby has downs syndrome
wolffd@0 40 tbl = zeros(2,1);
wolffd@0 41 p = 1/1000; % from www.downs-syndrome.org.uk figure
wolffd@0 42 p = 24/10000; % www-personal.umich.edu/~bobwolfe/560/review/Downs.pdf (for women agen 35-40)
wolffd@0 43 tbl(healthy) = 1-p;
wolffd@0 44 tbl(downs) = p;
wolffd@0 45 limid.CPD{B0} = tabular_CPD(limid, B0, tbl);
wolffd@0 46
wolffd@0 47 % Reliability of triple screen test
wolffd@0 48 % Unreliable sensor
wolffd@0 49 % B0 -> Rtriple
wolffd@0 50 tbl = zeros(2,2); % Rtriple = pos, neg
wolffd@0 51 p = 0.5; % high false positive rate (guess)
wolffd@0 52 tbl(healthy, :) = [p 1-p];
wolffd@0 53 p = 0.6; % low detection rate (march of dimes figure)
wolffd@0 54 tbl(downs, :) = [p 1-p];
wolffd@0 55 limid.CPD{Rtriple} = tabular_CPD(limid, Rtriple, tbl);
wolffd@0 56
wolffd@0 57 limid.CPD{Damnio} = tabular_decision_node(limid, Damnio);
wolffd@0 58
wolffd@0 59 % Effect of amnio on baby B0,Damnio -> B1
wolffd@0 60 % 1/200 risk of miscarry
wolffd@0 61 p = 1/200; % (march of dimes figure)
wolffd@0 62 tbl = zeros(2, 2, 3); % B1 = healthy, downs, miscarry
wolffd@0 63 tbl(healthy, no, :) = [1 0 0];
wolffd@0 64 tbl(downs, no, :) = [0 1 0];
wolffd@0 65 tbl(healthy, yes, :) = [1-p 0 p];
wolffd@0 66 tbl(downs, yes, :) = [0 1-p p];
wolffd@0 67 limid.CPD{B1} = tabular_CPD(limid, B1, tbl);
wolffd@0 68
wolffd@0 69 % Reliability of amnio B0, Damnio -> Ramnio
wolffd@0 70 % Perfect sensor
wolffd@0 71 tbl = zeros(2,2,3); % Ramnio = pos, neg, unk
wolffd@0 72 tbl(:, no, :) = repmat([0 0 1], 2 ,1);
wolffd@0 73 tbl(healthy, yes, :) = [0 1 0];
wolffd@0 74 tbl(downs, yes, :) = [1 0 0];
wolffd@0 75 limid.CPD{Ramnio} = tabular_CPD(limid, Ramnio, tbl);
wolffd@0 76
wolffd@0 77 limid.CPD{Dabort} = tabular_decision_node(limid, Dabort);
wolffd@0 78
wolffd@0 79 % Effect of abortion on baby B1, Dabort -> B2
wolffd@0 80 tbl = zeros(3, 2, 4); % B2 = healthy, downs, miscarry, aborted
wolffd@0 81 tbl(:, yes, :) = repmat([0 0 0 1], 3, 1);
wolffd@0 82 tbl(healthy, no, :) = [1 0 0 0];
wolffd@0 83 tbl(downs, no, :) = [0 1 0 0];
wolffd@0 84 tbl(miscarry, no, :) = [0 0 1 0];
wolffd@0 85 limid.CPD{B2} = tabular_CPD(limid, B2, tbl);
wolffd@0 86
wolffd@0 87 % Utility U(Ramnio, B2)
wolffd@0 88 tbl = zeros(3, 4);
wolffd@0 89 tbl(:, healthy) = 5000;
wolffd@0 90 tbl(:, downs) = -50000;
wolffd@0 91 tbl(:, miscarry) = -1000;
wolffd@0 92 tbl(:, aborted) = -1000;
wolffd@0 93
wolffd@0 94 if 0
wolffd@0 95 %tbl(unk, miscarry) = 0; % this case is impossible
wolffd@0 96 tbl(pos, miscarry) = -1;
wolffd@0 97 tbl(neg, miscarry) = -1000;
wolffd@0 98 if 1
wolffd@0 99 tbl(unk, aborted) = -100;
wolffd@0 100 tbl(pos, aborted) = -1;
wolffd@0 101 tbl(neg, aborted) = -500;
wolffd@0 102 else % pro-life utility fn
wolffd@0 103 tbl(unk, aborted) = -500000;
wolffd@0 104 tbl(pos, aborted) = -500000;
wolffd@0 105 tbl(neg, aborted) = -500000;
wolffd@0 106 end
wolffd@0 107 end
wolffd@0 108
wolffd@0 109 limid.CPD{U} = tabular_utility_node(limid, U, tbl);
wolffd@0 110
wolffd@0 111
wolffd@0 112
wolffd@0 113 engine = jtree_limid_inf_engine(limid);
wolffd@0 114 [strategy, MEU] = solve_limid(engine);
wolffd@0 115
wolffd@0 116 % Rtriple U(Damnio=1=yes) U(Damnio=2=no)
wolffd@0 117 % 1=pos 0 1
wolffd@0 118 % 2=neg 0 1
wolffd@0 119 dispcpt(strategy{Damnio})
wolffd@0 120 if isequal(strategy{Damnio}(1,:), strategy{Damnio}(2,:))
wolffd@0 121 % Rtriple result irrelevant
wolffd@0 122 doAmnio = argmax(strategy{Damnio}(1,:))
wolffd@0 123 else
wolffd@0 124 doAmnio = 1;
wolffd@0 125 end
wolffd@0 126
wolffd@0 127 % Rtriple Ramnio U(Dabort=yes=1) U(Dabort=no=2)
wolffd@0 128 % 1=pos 1=pos 1 0
wolffd@0 129 % 2=neg 1=pos 1 0
wolffd@0 130 % 1=pos 2=neg 0 1
wolffd@0 131 % 2=neg 2=neg 0 1
wolffd@0 132 % 1=pos 3=unk 0 1
wolffd@0 133 % 2=neg 3=unk 0 1
wolffd@0 134 dispcpt(strategy{Dabort})
wolffd@0 135