annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/Models/mk_cancer_bnet.m @ 0:cc4b1211e677 tip

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