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