Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/static/Models/mk_asia_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 = mk_asia_bnet(CPD_type, p, arity) | |
2 % MK_ASIA_BNET Make the 'Asia' bayes net. | |
3 % | |
4 % BNET = MK_ASIA_BNET uses the parameters specified on p21 of Cowell et al, | |
5 % "Probabilistic networks and expert systems", Springer Verlag 1999. | |
6 % | |
7 % BNET = MK_ASIA_BNET('cpt', p) uses random parameters drawn from a Dirichlet(p,p,...) | |
8 % distribution. If p << 1, this is nearly deterministic; if p >> 1, this is nearly uniform. | |
9 % | |
10 % BNET = MK_ASIA_BNET('bool') makes each CPT a random boolean function. | |
11 % | |
12 % BNET = MK_ASIA_BNET('gauss') makes each CPT a random linear Gaussian distribution. | |
13 % | |
14 % BNET = MK_ASIA_BNET('orig') is the same as MK_ASIA_BNET. | |
15 % | |
16 % BNET = MK_ASIA_BNET('cpt', p, arity) can specify non-binary nodes. | |
17 | |
18 | |
19 if nargin == 0, CPD_type = 'orig'; end | |
20 if nargin < 3, arity = 2; end | |
21 | |
22 Smoking = 1; | |
23 Bronchitis = 2; | |
24 LungCancer = 3; | |
25 VisitToAsia = 4; | |
26 TB = 5; | |
27 TBorCancer = 6; | |
28 Dys = 7; | |
29 Xray = 8; | |
30 | |
31 n = 8; | |
32 dag = zeros(n); | |
33 dag(Smoking, [Bronchitis LungCancer]) = 1; | |
34 dag(Bronchitis, Dys) = 1; | |
35 dag(LungCancer, TBorCancer) = 1; | |
36 dag(VisitToAsia, TB) = 1; | |
37 dag(TB, TBorCancer) = 1; | |
38 dag(TBorCancer, [Dys Xray]) = 1; | |
39 | |
40 ns = arity*ones(1,n); | |
41 if strcmp(CPD_type, 'gauss') | |
42 dnodes = []; | |
43 else | |
44 dnodes = 1:n; | |
45 end | |
46 bnet = mk_bnet(dag, ns, 'discrete', dnodes); | |
47 | |
48 switch CPD_type | |
49 case 'orig', | |
50 % true is 2, false is 1 | |
51 bnet.CPD{VisitToAsia} = tabular_CPD(bnet, VisitToAsia, [0.99 0.01]); | |
52 bnet.CPD{Bronchitis} = tabular_CPD(bnet, Bronchitis, [0.7 0.4 0.3 0.6]); | |
53 % minka: bug fix | |
54 bnet.CPD{Dys} = tabular_CPD(bnet, Dys, [0.9 0.2 0.3 0.1 0.1 0.8 0.7 0.9]); | |
55 bnet.CPD{TBorCancer} = tabular_CPD(bnet, TBorCancer, [1 0 0 0 0 1 1 1]); | |
56 % minka: bug fix | |
57 bnet.CPD{LungCancer} = tabular_CPD(bnet, LungCancer, [0.99 0.9 0.01 0.1]); | |
58 bnet.CPD{Smoking} = tabular_CPD(bnet, Smoking, [0.5 0.5]); | |
59 bnet.CPD{TB} = tabular_CPD(bnet, TB, [0.99 0.95 0.01 0.05]); | |
60 bnet.CPD{Xray} = tabular_CPD(bnet, Xray, [0.95 0.02 0.05 0.98]); | |
61 case 'bool', | |
62 for i=1:n | |
63 bnet.CPD{i} = boolean_CPD(bnet, i, 'rnd'); | |
64 end | |
65 case 'gauss', | |
66 for i=1:n | |
67 bnet.CPD{i} = gaussian_CPD(bnet, i, 'cov', 1*eye(ns(i))); | |
68 end | |
69 case 'cpt', | |
70 for i=1:n | |
71 bnet.CPD{i} = tabular_CPD(bnet, i, p); | |
72 end | |
73 end | |
74 | |
75 | |
76 |