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