annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/Models/mk_cancer_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_cancer_bnet(CPD_type, p)
wolffd@0 2 % MK_CANCER_BNET Make the 'Cancer' Bayes net.
wolffd@0 3 %
wolffd@0 4 % BNET = MK_CANCER_BNET uses the noisy-or parameters specified in Fig 4a of the UAI98 paper by
wolffd@0 5 % Friedman, Murphy and Russell, "Learning the Structure of DPNs", p145.
wolffd@0 6 %
wolffd@0 7 % BNET = MK_CANCER_BNET('noisyor', p) makes each CPD a noisy-or, with probability p of
wolffd@0 8 % suppression for each parent; leaks are turned off.
wolffd@0 9 %
wolffd@0 10 % BNET = MK_CANCER_BNET('cpt', p) uses random CPT parameters drawn from a Dirichlet(p,p,...)
wolffd@0 11 % distribution. If p << 1, this is near deterministic; if p >> 1, this is near 1/k.
wolffd@0 12 % p defaults to 1.0 (uniform distribution).
wolffd@0 13 %
wolffd@0 14 % BNET = MK_CANCER_BNET('bool') makes each CPT a random boolean function.
wolffd@0 15 %
wolffd@0 16 % In all cases, the root is set to a uniform distribution.
wolffd@0 17
wolffd@0 18 if nargin == 0
wolffd@0 19 rnd = 0;
wolffd@0 20 else
wolffd@0 21 rnd = 1;
wolffd@0 22 end
wolffd@0 23
wolffd@0 24 n = 5;
wolffd@0 25 dag = zeros(n);
wolffd@0 26 dag(1,[2 3]) = 1;
wolffd@0 27 dag(2,4) = 1;
wolffd@0 28 dag(3,4) = 1;
wolffd@0 29 dag(4,5) = 1;
wolffd@0 30
wolffd@0 31 ns = 2*ones(1,n);
wolffd@0 32 bnet = mk_bnet(dag, ns);
wolffd@0 33
wolffd@0 34 if ~rnd
wolffd@0 35 bnet.CPD{1} = tabular_CPD(bnet, 1, [0.5 0.5]);
wolffd@0 36 bnet.CPD{2} = noisyor_CPD(bnet, 2, 1.0, 1-0.9);
wolffd@0 37 bnet.CPD{3} = noisyor_CPD(bnet, 3, 1.0, 1-0.2);
wolffd@0 38 bnet.CPD{4} = noisyor_CPD(bnet, 4, 1.0, 1-[0.7 0.6]);
wolffd@0 39 bnet.CPD{5} = noisyor_CPD(bnet, 5, 1.0, 1-0.5);
wolffd@0 40 else
wolffd@0 41 switch CPD_type
wolffd@0 42 case 'noisyor',
wolffd@0 43 for i=1:n
wolffd@0 44 ps = parents(dag, i);
wolffd@0 45 bnet.CPD{i} = noisyor_CPD(bnet, i, 1.0, p*ones(1,length(ps)));
wolffd@0 46 end
wolffd@0 47 case 'bool',
wolffd@0 48 for i=1:n
wolffd@0 49 bnet.CPD{i} = boolean_CPD(bnet, i, 'rnd');
wolffd@0 50 end
wolffd@0 51 case 'cpt',
wolffd@0 52 for i=1:n
wolffd@0 53 bnet.CPD{i} = tabular_CPD(bnet, i, p);
wolffd@0 54 end
wolffd@0 55 otherwise
wolffd@0 56 error(['bad CPD type ' CPD_type]);
wolffd@0 57 end
wolffd@0 58 end
wolffd@0 59
wolffd@0 60
wolffd@0 61