wolffd@0: function bnet = mk_asia_bnet(CPD_type, p, arity) wolffd@0: % MK_ASIA_BNET Make the 'Asia' bayes net. wolffd@0: % wolffd@0: % BNET = MK_ASIA_BNET uses the parameters specified on p21 of Cowell et al, wolffd@0: % "Probabilistic networks and expert systems", Springer Verlag 1999. wolffd@0: % wolffd@0: % BNET = MK_ASIA_BNET('cpt', p) uses random parameters drawn from a Dirichlet(p,p,...) wolffd@0: % distribution. If p << 1, this is nearly deterministic; if p >> 1, this is nearly uniform. wolffd@0: % wolffd@0: % BNET = MK_ASIA_BNET('bool') makes each CPT a random boolean function. wolffd@0: % wolffd@0: % BNET = MK_ASIA_BNET('gauss') makes each CPT a random linear Gaussian distribution. wolffd@0: % wolffd@0: % BNET = MK_ASIA_BNET('orig') is the same as MK_ASIA_BNET. wolffd@0: % wolffd@0: % BNET = MK_ASIA_BNET('cpt', p, arity) can specify non-binary nodes. wolffd@0: wolffd@0: wolffd@0: if nargin == 0, CPD_type = 'orig'; end wolffd@0: if nargin < 3, arity = 2; end wolffd@0: wolffd@0: Smoking = 1; wolffd@0: Bronchitis = 2; wolffd@0: LungCancer = 3; wolffd@0: VisitToAsia = 4; wolffd@0: TB = 5; wolffd@0: TBorCancer = 6; wolffd@0: Dys = 7; wolffd@0: Xray = 8; wolffd@0: wolffd@0: n = 8; wolffd@0: dag = zeros(n); wolffd@0: dag(Smoking, [Bronchitis LungCancer]) = 1; wolffd@0: dag(Bronchitis, Dys) = 1; wolffd@0: dag(LungCancer, TBorCancer) = 1; wolffd@0: dag(VisitToAsia, TB) = 1; wolffd@0: dag(TB, TBorCancer) = 1; wolffd@0: dag(TBorCancer, [Dys Xray]) = 1; wolffd@0: wolffd@0: ns = arity*ones(1,n); wolffd@0: if strcmp(CPD_type, 'gauss') wolffd@0: dnodes = []; wolffd@0: else wolffd@0: dnodes = 1:n; wolffd@0: end wolffd@0: bnet = mk_bnet(dag, ns, 'discrete', dnodes); wolffd@0: wolffd@0: switch CPD_type wolffd@0: case 'orig', wolffd@0: % true is 2, false is 1 wolffd@0: bnet.CPD{VisitToAsia} = tabular_CPD(bnet, VisitToAsia, [0.99 0.01]); wolffd@0: bnet.CPD{Bronchitis} = tabular_CPD(bnet, Bronchitis, [0.7 0.4 0.3 0.6]); wolffd@0: % minka: bug fix wolffd@0: 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: bnet.CPD{TBorCancer} = tabular_CPD(bnet, TBorCancer, [1 0 0 0 0 1 1 1]); wolffd@0: % minka: bug fix wolffd@0: bnet.CPD{LungCancer} = tabular_CPD(bnet, LungCancer, [0.99 0.9 0.01 0.1]); wolffd@0: bnet.CPD{Smoking} = tabular_CPD(bnet, Smoking, [0.5 0.5]); wolffd@0: bnet.CPD{TB} = tabular_CPD(bnet, TB, [0.99 0.95 0.01 0.05]); wolffd@0: bnet.CPD{Xray} = tabular_CPD(bnet, Xray, [0.95 0.02 0.05 0.98]); wolffd@0: case 'bool', wolffd@0: for i=1:n wolffd@0: bnet.CPD{i} = boolean_CPD(bnet, i, 'rnd'); wolffd@0: end wolffd@0: case 'gauss', wolffd@0: for i=1:n wolffd@0: bnet.CPD{i} = gaussian_CPD(bnet, i, 'cov', 1*eye(ns(i))); wolffd@0: end wolffd@0: case 'cpt', wolffd@0: for i=1:n wolffd@0: bnet.CPD{i} = tabular_CPD(bnet, i, p); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: