Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/Models/mk_minimal_qmr_bnet.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 function [bnet, vals] = mk_minimal_qmr_bnet(G, inhibit, leak, prior, pos, neg, pos_only) | |
2 % MK_MINIMAL_QMR_BNET Make a QMR model which only contains the observed findings | |
3 % [bnet, vals] = mk_minimal_qmr_bnet(G, inhibit, prior, leak, pos, neg) | |
4 % | |
5 % Input: | |
6 % G(i,j) = 1 iff there is an arc from disease i to finding j | |
7 % inhibit(i,j) = inhibition probability on i->j arc | |
8 % leak(j) = inhibition prob. on leak->j arc | |
9 % prior(i) = prob. disease i is on | |
10 % pos = list of leaves that have positive observations | |
11 % neg = list of leaves that have negative observations | |
12 % pos_only = 1 means only include positively observed leaves in the model - the negative | |
13 % ones are absorbed into the prior terms | |
14 % | |
15 % Output: | |
16 % bnet | |
17 % vals is their value | |
18 | |
19 if pos_only | |
20 obs = pos; | |
21 else | |
22 obs = myunion(pos, neg); | |
23 end | |
24 Nfindings = length(obs); | |
25 [Ndiseases maxNfindings] = size(inhibit); | |
26 N = Ndiseases + Nfindings; | |
27 finding_node = Ndiseases+1:N; | |
28 | |
29 % j = finding_node(i) means the i'th finding node is the j'th node in the bnet | |
30 % k = obs(i) means the i'th observed (positive) finding is the k'th finding overall | |
31 % If all findings are observed, and posonly = 0, we have i = obs(i) for all i. | |
32 | |
33 %dag = sparse(N, N); | |
34 dag = zeros(N, N); | |
35 dag(1:Ndiseases, Ndiseases+1:N) = G(:,obs); | |
36 | |
37 ns = 2*ones(1,N); | |
38 bnet = mk_bnet(dag, ns, 'observed', finding_node); | |
39 | |
40 CPT = cell(1, Ndiseases); | |
41 for d=1:Ndiseases | |
42 CPT{d} = [1-prior(d) prior(d)]; | |
43 end | |
44 | |
45 if pos_only | |
46 % Fold in the negative evidence into the prior | |
47 for i=1:length(neg) | |
48 n = neg(i); | |
49 ps = parents(G,n); | |
50 for pi=1:length(ps) | |
51 p = ps(pi); | |
52 q = inhibit(p,n); | |
53 CPT{p} = CPT{p} .* [1 q]; | |
54 end | |
55 % Arbitrarily attach the leak term to the first parent | |
56 p = ps(1); | |
57 q = leak(n); | |
58 CPT{p} = CPT{p} .* [q q]; | |
59 end | |
60 end | |
61 | |
62 for d=1:Ndiseases | |
63 bnet.CPD{d} = tabular_CPD(bnet, d, CPT{d}'); | |
64 end | |
65 | |
66 for i=1:Nfindings | |
67 fnode = finding_node(i); | |
68 fid = obs(i); | |
69 ps = parents(G, fid); | |
70 bnet.CPD{fnode} = noisyor_CPD(bnet, fnode, leak(fid), inhibit(ps, fid)); | |
71 end | |
72 | |
73 obs_nodes = finding_node; | |
74 vals = sparse(1, maxNfindings); | |
75 vals(pos) = 2; | |
76 vals(neg) = 1; | |
77 vals = full(vals(obs)); | |
78 | |
79 | |
80 | |
81 | |
82 |