diff options
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/static/Models')
18 files changed, 698 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Entries new file mode 100644 index 00000000..398be87c --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Entries @@ -0,0 +1,12 @@ +/mk_alarm_bnet.m/1.1.1.1/Sun Nov 3 16:44:14 2002// +/mk_asia_bnet.m/1.1.1.1/Wed Mar 26 00:06:42 2003// +/mk_cancer_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_car_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_hmm_bnet.m/1.1.1.1/Thu Jan 15 01:06:12 2004// +/mk_ideker_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_incinerator_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_markov_chain_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_minimal_qmr_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_qmr_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +/mk_vstruct_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +D/Old//// diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Repository new file mode 100644 index 00000000..2218a7f5 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/examples/static/Models diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Root b/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Entries new file mode 100644 index 00000000..c7e92b5c --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Entries @@ -0,0 +1,2 @@ +/mk_hmm_bnet.m/1.1.1.1/Wed May 29 15:59:54 2002// +D diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Repository new file mode 100644 index 00000000..fdee291b --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/examples/static/Models/Old diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/Old/mk_hmm_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/mk_hmm_bnet.m new file mode 100644 index 00000000..1179c6d8 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/Old/mk_hmm_bnet.m @@ -0,0 +1,58 @@ +function [bnet, onodes] = mk_hmm_bnet(T, Q, O, cts_obs, param_tying) +% MK_HMM_BNET Make a (static( bnet to represent a hidden Markov model +% [bnet, onodes] = mk_hmm_bnet(T, Q, O, cts_obs, param_tying) +% +% T = num time slices +% Q = num hidden states +% O = size of the observed node (num discrete values or length of vector) +% cts_obs - 1 means the observed node is a continuous-valued vector, 0 means it's discrete +% param_tying - 1 means we create 3 CPDs, 0 means we create 1 CPD per node + +N = 2*T; +dag = zeros(N); +for i=1:T-1 + dag(i,i+1)=1; +end +onodes = T+1:N; +for i=1:T + dag(i, onodes(i)) = 1; +end + +if cts_obs + dnodes = 1:T; +else + dnodes = 1:N; +end +ns = [Q*ones(1,T) O*ones(1,T)]; + +if param_tying + eclass = [1 2*ones(1,T-1) 3*ones(1,T)]; +else + eclass = 1:N; +end + +bnet = mk_bnet(dag, ns, dnodes, eclass); + +hnodes = mysetdiff(1:N, onodes); +if ~param_tying + for i=hnodes(:)' + bnet.CPD{i} = tabular_CPD(bnet, i); + end + if cts_obs + for i=onodes(:)' + bnet.CPD{i} = gaussian_CPD(bnet, i); + end + else + for i=onodes(:)' + bnet.CPD{i} = tabular_CPD(bnet, i); + end + end +else + bnet.CPD{1} = tabular_CPD(bnet, 1); + bnet.CPD{2} = tabular_CPD(bnet, 2); + if cts_obs + bnet.CPD{3} = gaussian_CPD(bnet, 3); + else + bnet.CPD{3} = tabular_CPD(bnet, 3); + end +end diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_alarm_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_alarm_bnet.m new file mode 100644 index 00000000..5705909b --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_alarm_bnet.m @@ -0,0 +1,118 @@ +function bnet = mk_alarm_bnet() + +% Written by Qian Diao <qian.diao@intel.com> on 11 Dec 01 + +N = 37; +dag = zeros(N,N); +dag(21,23) = 1 ; +dag(21,24) = 1 ; +dag(1,24) = 1 ; +dag(1,23) = 1 ; +dag(2,26) = 1 ; +dag(2,25) = 1 ; +dag(2,24) = 1 ; +dag(2,13) = 1 ; +dag(2,23) = 1 ; +dag(13,30) = 1 ; +dag(30,31) = 1 ; +dag(3,14) = 1 ; +dag(3,19) = 1 ; +dag(4,36) = 1 ; +dag(14,35) = 1 ; +dag(32,33) = 1 ; +dag(32,35) = 1 ; +dag(32,34) = 1 ; +dag(32,36) = 1 ; +dag(15,21) = 1 ; +dag(5,31) = 1 ; +dag(27,30) = 1 ; +dag(28,31) = 1 ; +dag(28,29) = 1 ; +dag(26,28) = 1 ; +dag(26,27) = 1 ; +dag(16,31) = 1 ; +dag(16,37) = 1 ; +dag(23,26) = 1 ; +dag(23,29) = 1 ; +dag(23,25) = 1 ; +dag(6,15) = 1 ; +dag(7,27) = 1 ; +dag(8,21) = 1 ; +dag(19,20) = 1 ; +dag(19,22) = 1 ; +dag(31,32) = 1 ; +dag(9,14) = 1 ; +dag(9,17) = 1 ; +dag(9,19) = 1 ; +dag(10,33) = 1 ; +dag(10,34) = 1 ; +dag(11,16) = 1 ; +dag(12,13) = 1 ; +dag(12,18) = 1 ; +dag(35,37) = 1 ; + +node_sizes = 2*ones(1,N); +node_sizes(2) = 3; +node_sizes(6) = 3; +node_sizes(14) = 3; +node_sizes(15) = 4; +node_sizes(16) = 3; +node_sizes(18) = 3; +node_sizes(19) = 3; +node_sizes(20) = 3; +node_sizes(21) = 4; +node_sizes(22) = 3; +node_sizes(23) = 4; +node_sizes(24) = 4; +node_sizes(25) = 4; +node_sizes(26) = 4; +node_sizes(27) = 3; +node_sizes(28) = 3; +node_sizes(29) = 4; +node_sizes(30) = 3; +node_sizes(32) = 3; +node_sizes(33) = 3; +node_sizes(34) = 3; +node_sizes(35) = 3; +node_sizes(36) = 3; +node_sizes(37) = 3; + +bnet = mk_bnet(dag, node_sizes); + +bnet.CPD{1} = tabular_CPD(bnet, 1,[0.96 0.04 ]); +bnet.CPD{2} = tabular_CPD(bnet, 2,[0.92 0.03 0.05 ]); +bnet.CPD{3} = tabular_CPD(bnet, 3,[0.8 0.2 ]); +bnet.CPD{4} = tabular_CPD(bnet, 4,[0.95 0.05 ]); +bnet.CPD{5} = tabular_CPD(bnet, 5,[0.8 0.2 ]); +bnet.CPD{6} = tabular_CPD(bnet, 6,[0.01 0.98 0.01 ]); +bnet.CPD{7} = tabular_CPD(bnet, 7,[0.01 0.99 ]); +bnet.CPD{8} = tabular_CPD(bnet, 8,[0.95 0.05 ]); +bnet.CPD{9} = tabular_CPD(bnet, 9,[0.95 0.05 ]); +bnet.CPD{10} = tabular_CPD(bnet, 10,[0.9 0.1 ]); +bnet.CPD{11} = tabular_CPD(bnet, 11,[0.99 0.01 ]); +bnet.CPD{12} = tabular_CPD(bnet, 12,[0.99 0.01 ]); +bnet.CPD{13} = tabular_CPD(bnet, 13,[0.95 0.95 0.05 0.1 0.1 0.01 0.05 0.05 0.95 0.9 0.9 0.99 ]); +bnet.CPD{14} = tabular_CPD(bnet, 14,[0.05 0.95 0.5 0.98 0.9 0.04 0.49 0.01 0.05 0.01 0.01 0.01 ]); +bnet.CPD{15} = tabular_CPD(bnet, 15,[0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.97 ]); +bnet.CPD{16} = tabular_CPD(bnet, 16,[0.3 0.98 0.4 0.01 0.3 0.01 ]); +bnet.CPD{17} = tabular_CPD(bnet, 17,[0.99 0.1 0.01 0.9 ]); +bnet.CPD{18} = tabular_CPD(bnet, 18,[0.05 0.01 0.9 0.19 0.05 0.8 ]); +bnet.CPD{19} = tabular_CPD(bnet, 19,[0.05 0.98 0.01 0.95 0.9 0.01 0.09 0.04 0.05 0.01 0.9 0.01 ]); +bnet.CPD{20} = tabular_CPD(bnet, 20,[0.95 0.04 0.01 0.04 0.95 0.29 0.01 0.01 0.7 ]); +bnet.CPD{21} = tabular_CPD(bnet, 21,[0.97 0.97 0.01 0.97 0.01 0.97 0.01 0.97 0.01 0.01 0.97 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.01 ]); +bnet.CPD{22} = tabular_CPD(bnet, 22,[0.95 0.04 0.01 0.04 0.95 0.04 0.01 0.01 0.95 ]); +bnet.CPD{23} = tabular_CPD(bnet, 23,[0.97 0.97 0.97 0.97 0.97 0.97 0.01 0.95 0.97 0.97 0.01 0.95 0.01 0.4 0.97 0.97 0.01 0.5 0.01 0.3 0.97 0.97 0.01 0.3 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.03 0.01 0.01 0.97 0.03 0.01 0.58 0.01 0.01 0.01 0.48 0.01 0.68 0.01 0.01 0.01 0.68 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.97 0.01 ]); +bnet.CPD{24} = tabular_CPD(bnet, 24,[0.97 0.97 0.97 0.97 0.97 0.97 0.01 0.01 0.4 0.1 0.01 0.01 0.01 0.01 0.2 0.05 0.01 0.01 0.01 0.01 0.2 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.49 0.58 0.84 0.9 0.29 0.01 0.01 0.75 0.25 0.01 0.01 0.01 0.01 0.7 0.15 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.3 0.01 0.05 0.08 0.3 0.97 0.08 0.04 0.25 0.38 0.08 0.01 0.01 0.09 0.25 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.2 0.01 0.01 0.01 0.4 0.01 0.9 0.01 0.45 0.6 0.9 0.97 0.97 0.01 0.59 0.97 0.97 ]); +bnet.CPD{25} = tabular_CPD(bnet, 25,[0.97 0.97 0.97 0.01 0.6 0.01 0.01 0.5 0.01 0.01 0.5 0.01 0.01 0.01 0.01 0.97 0.38 0.97 0.01 0.48 0.01 0.01 0.48 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.01 0.97 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.01 0.97 ]); +bnet.CPD{26} = tabular_CPD(bnet, 26,[0.97 0.97 0.97 0.01 0.01 0.03 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.01 0.01 0.97 0.97 0.95 0.01 0.01 0.94 0.01 0.01 0.88 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.97 0.04 0.01 0.01 0.1 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.97 0.01 ]); +bnet.CPD{27} = tabular_CPD(bnet, 27,[0.98 0.98 0.98 0.98 0.95 0.01 0.95 0.01 0.01 0.01 0.01 0.01 0.04 0.95 0.04 0.01 0.01 0.01 0.01 0.01 0.01 0.04 0.01 0.98 ]); +bnet.CPD{28} = tabular_CPD(bnet, 28,[0.01 0.01 0.04 0.9 0.01 0.01 0.92 0.09 0.98 0.98 0.04 0.01 ]); +bnet.CPD{29} = tabular_CPD(bnet, 29,[0.97 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.97 0.01 0.01 0.01 0.01 0.97 0.97 0.97 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.97 0.97 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.97 0.97 0.43 ]); +bnet.CPD{30} = tabular_CPD(bnet, 30,[0.98 0.98 0.01 0.98 0.01 0.69 0.01 0.01 0.98 0.01 0.01 0.3 0.01 0.01 0.01 0.01 0.98 0.01 ]); +bnet.CPD{31} = tabular_CPD(bnet, 31,[0.05 0.01 0.05 0.01 0.05 0.01 0.05 0.01 0.05 0.01 0.05 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.1 0.01 0.95 0.01 0.95 0.05 0.1 0.01 0.95 0.01 0.95 0.05 0.1 0.01 0.3 0.01 0.3 0.01 0.95 0.01 0.99 0.05 0.95 0.05 0.95 0.01 0.99 0.05 0.99 0.05 0.3 0.01 0.99 0.01 0.3 0.01 0.95 0.99 0.95 0.99 0.95 0.99 0.95 0.99 0.95 0.99 0.95 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.9 0.99 0.05 0.99 0.05 0.95 0.9 0.99 0.05 0.99 0.05 0.95 0.9 0.99 0.7 0.99 0.7 0.99 0.05 0.99 0.00999999 0.95 0.05 0.95 0.05 0.99 0.01 0.95 0.01 0.95 0.7 0.99 0.01 0.99 0.7 0.99 ]); +bnet.CPD{32} = tabular_CPD(bnet, 32,[0.1 0.01 0.89 0.09 0.01 0.9 ]); +bnet.CPD{33} = tabular_CPD(bnet, 33,[0.98 0.33333334 0.01 0.33333334 0.01 0.33333334 0.01 0.33333334 0.98 0.33333334 0.01 0.33333334 0.01 0.33333334 0.01 0.33333334 0.98 0.33333334 ]); +bnet.CPD{34} = tabular_CPD(bnet, 34,[0.98 0.33333334 0.01 0.33333334 0.01 0.33333334 0.01 0.33333334 0.98 0.33333334 0.01 0.33333334 0.01 0.33333334 0.01 0.33333334 0.98 0.33333334 ]); +bnet.CPD{35} = tabular_CPD(bnet, 35,[0.98 0.95 0.3 0.95 0.04 0.01 0.8 0.01 0.01 0.01 0.04 0.69 0.04 0.95 0.3 0.19 0.04 0.01 0.01 0.01 0.01 0.01 0.01 0.69 0.01 0.95 0.98 ]); +bnet.CPD{36} = tabular_CPD(bnet, 36,[0.98 0.98 0.01 0.4 0.01 0.3 0.01 0.01 0.98 0.59 0.01 0.4 0.01 0.01 0.01 0.01 0.98 0.3 ]); +bnet.CPD{37} = tabular_CPD(bnet, 37,[0.98 0.98 0.3 0.98 0.1 0.05 0.9 0.05 0.01 0.01 0.01 0.6 0.01 0.85 0.4 0.09 0.2 0.09 0.01 0.01 0.1 0.01 0.05 0.55 0.01 0.75 0.9 ]); diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_asia_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_asia_bnet.m new file mode 100644 index 00000000..fce24c3a --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_asia_bnet.m @@ -0,0 +1,76 @@ +function bnet = mk_asia_bnet(CPD_type, p, arity) +% MK_ASIA_BNET Make the 'Asia' bayes net. +% +% BNET = MK_ASIA_BNET uses the parameters specified on p21 of Cowell et al, +% "Probabilistic networks and expert systems", Springer Verlag 1999. +% +% BNET = MK_ASIA_BNET('cpt', p) uses random parameters drawn from a Dirichlet(p,p,...) +% distribution. If p << 1, this is nearly deterministic; if p >> 1, this is nearly uniform. +% +% BNET = MK_ASIA_BNET('bool') makes each CPT a random boolean function. +% +% BNET = MK_ASIA_BNET('gauss') makes each CPT a random linear Gaussian distribution. +% +% BNET = MK_ASIA_BNET('orig') is the same as MK_ASIA_BNET. +% +% BNET = MK_ASIA_BNET('cpt', p, arity) can specify non-binary nodes. + + +if nargin == 0, CPD_type = 'orig'; end +if nargin < 3, arity = 2; end + +Smoking = 1; +Bronchitis = 2; +LungCancer = 3; +VisitToAsia = 4; +TB = 5; +TBorCancer = 6; +Dys = 7; +Xray = 8; + +n = 8; +dag = zeros(n); +dag(Smoking, [Bronchitis LungCancer]) = 1; +dag(Bronchitis, Dys) = 1; +dag(LungCancer, TBorCancer) = 1; +dag(VisitToAsia, TB) = 1; +dag(TB, TBorCancer) = 1; +dag(TBorCancer, [Dys Xray]) = 1; + +ns = arity*ones(1,n); +if strcmp(CPD_type, 'gauss') + dnodes = []; +else + dnodes = 1:n; +end +bnet = mk_bnet(dag, ns, 'discrete', dnodes); + +switch CPD_type + case 'orig', + % true is 2, false is 1 + bnet.CPD{VisitToAsia} = tabular_CPD(bnet, VisitToAsia, [0.99 0.01]); + bnet.CPD{Bronchitis} = tabular_CPD(bnet, Bronchitis, [0.7 0.4 0.3 0.6]); + % minka: bug fix + bnet.CPD{Dys} = tabular_CPD(bnet, Dys, [0.9 0.2 0.3 0.1 0.1 0.8 0.7 0.9]); + bnet.CPD{TBorCancer} = tabular_CPD(bnet, TBorCancer, [1 0 0 0 0 1 1 1]); + % minka: bug fix + bnet.CPD{LungCancer} = tabular_CPD(bnet, LungCancer, [0.99 0.9 0.01 0.1]); + bnet.CPD{Smoking} = tabular_CPD(bnet, Smoking, [0.5 0.5]); + bnet.CPD{TB} = tabular_CPD(bnet, TB, [0.99 0.95 0.01 0.05]); + bnet.CPD{Xray} = tabular_CPD(bnet, Xray, [0.95 0.02 0.05 0.98]); + case 'bool', + for i=1:n + bnet.CPD{i} = boolean_CPD(bnet, i, 'rnd'); + end + case 'gauss', + for i=1:n + bnet.CPD{i} = gaussian_CPD(bnet, i, 'cov', 1*eye(ns(i))); + end + case 'cpt', + for i=1:n + bnet.CPD{i} = tabular_CPD(bnet, i, p); + end +end + + + diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_cancer_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_cancer_bnet.m new file mode 100644 index 00000000..c54cbfad --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_cancer_bnet.m @@ -0,0 +1,61 @@ +function bnet = mk_cancer_bnet(CPD_type, p) +% MK_CANCER_BNET Make the 'Cancer' Bayes net. +% +% BNET = MK_CANCER_BNET uses the noisy-or parameters specified in Fig 4a of the UAI98 paper by +% Friedman, Murphy and Russell, "Learning the Structure of DPNs", p145. +% +% BNET = MK_CANCER_BNET('noisyor', p) makes each CPD a noisy-or, with probability p of +% suppression for each parent; leaks are turned off. +% +% BNET = MK_CANCER_BNET('cpt', p) uses random CPT parameters drawn from a Dirichlet(p,p,...) +% distribution. If p << 1, this is near deterministic; if p >> 1, this is near 1/k. +% p defaults to 1.0 (uniform distribution). +% +% BNET = MK_CANCER_BNET('bool') makes each CPT a random boolean function. +% +% In all cases, the root is set to a uniform distribution. + +if nargin == 0 + rnd = 0; +else + rnd = 1; +end + +n = 5; +dag = zeros(n); +dag(1,[2 3]) = 1; +dag(2,4) = 1; +dag(3,4) = 1; +dag(4,5) = 1; + +ns = 2*ones(1,n); +bnet = mk_bnet(dag, ns); + +if ~rnd + bnet.CPD{1} = tabular_CPD(bnet, 1, [0.5 0.5]); + bnet.CPD{2} = noisyor_CPD(bnet, 2, 1.0, 1-0.9); + bnet.CPD{3} = noisyor_CPD(bnet, 3, 1.0, 1-0.2); + bnet.CPD{4} = noisyor_CPD(bnet, 4, 1.0, 1-[0.7 0.6]); + bnet.CPD{5} = noisyor_CPD(bnet, 5, 1.0, 1-0.5); +else + switch CPD_type + case 'noisyor', + for i=1:n + ps = parents(dag, i); + bnet.CPD{i} = noisyor_CPD(bnet, i, 1.0, p*ones(1,length(ps))); + end + case 'bool', + for i=1:n + bnet.CPD{i} = boolean_CPD(bnet, i, 'rnd'); + end + case 'cpt', + for i=1:n + bnet.CPD{i} = tabular_CPD(bnet, i, p); + end + otherwise + error(['bad CPD type ' CPD_type]); + end +end + + + diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_car_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_car_bnet.m new file mode 100644 index 00000000..c9a27c9c --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_car_bnet.m @@ -0,0 +1,39 @@ +function bnet = mk_car_bnet() +% MK_CAR_BNET Make the car trouble-shooter bayes net. +% +% This network is from p13 of "Troubleshooting under uncertainty", Heckerman, Breese and +% Rommelse, Microsoft Research Tech Report 1994. + + +BatteryAge = 1; +Battery = 2; +Starter = 3; +Lights = 4; +TurnsOver = 5; +FuelPump = 6; +FuelLine = 7; +FuelSubsys =8; +Fuel = 9; +Spark = 10; +Starts = 11; +Gauge = 12; + +n = 12; +dag = zeros(n); +dag(1,2) = 1; +dag(2,[4 5])=1; +dag(3,5) = 1; +dag(6,8) = 1; +dag(7,8) = 1; +dag(8,11) = 1; +dag(9,12) = 1; +dag(10,11) = 1; + +arity = 2; +ns = arity*ones(1,n); +bnet = mk_bnet(dag, ns); +for i=1:n + bnet.CPD{i} = tabular_CPD(bnet, i); +end + + diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_hmm_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_hmm_bnet.m new file mode 100644 index 00000000..6e2dbfba --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_hmm_bnet.m @@ -0,0 +1,67 @@ +function bnet = mk_hmm_bnet(T, Q, O, cts_obs, param_tying) +% MK_HMM_BNET Make a (static) bnet to represent a hidden Markov model +% bnet = mk_hmm_bnet(T, Q, O, cts_obs, param_tying) +% +% T = num time slices +% Q = num hidden states +% O = size of the observed node (num discrete values or length of vector) +% cts_obs - 1 means the observed node is a continuous-valued vector, 0 means it's discrete +% param_tying - 1 means we create 3 CPDs, 0 means we create 1 CPD per node + +N = 2*T; +dag = zeros(N); +%hnodes = 1:2:2*T; +hnodes = 1:T; +for i=1:T-1 + dag(hnodes(i), hnodes(i+1))=1; +end +%onodes = 2:2:2*T; +onodes = T+1:2*T; +for i=1:T + dag(hnodes(i), onodes(i)) = 1; +end + +if cts_obs + dnodes = hnodes; +else + dnodes = 1:N; +end +ns = ones(1,N); +ns(hnodes) = Q; +ns(onodes) = O; + +if param_tying + H1class = 1; Hclass = 2; Oclass = 3; + eclass = ones(1,N); + eclass(hnodes(2:end)) = Hclass; + eclass(hnodes(1)) = H1class; + eclass(onodes) = Oclass; +else + eclass = 1:N; +end + +bnet = mk_bnet(dag, ns, 'observed', onodes, 'discrete', dnodes, 'equiv_class', eclass); + +hnodes = mysetdiff(1:N, onodes); +if ~param_tying + for i=hnodes(:)' + bnet.CPD{i} = tabular_CPD(bnet, i); + end + if cts_obs + for i=onodes(:)' + bnet.CPD{i} = gaussian_CPD(bnet, i); + end + else + for i=onodes(:)' + bnet.CPD{i} = tabular_CPD(bnet, i); + end + end +else + bnet.CPD{H1class} = tabular_CPD(bnet, hnodes(1)); % prior + bnet.CPD{Hclass} = tabular_CPD(bnet, hnodes(2)); % transition matrix + if cts_obs + bnet.CPD{Oclass} = gaussian_CPD(bnet, onodes(1)); + else + bnet.CPD{Oclass} = tabular_CPD(bnet, onodes(1)); + end +end diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_ideker_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_ideker_bnet.m new file mode 100644 index 00000000..67f95bae --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_ideker_bnet.m @@ -0,0 +1,52 @@ +function bnet = mk_ideker_bnet(CPD_type, p) +% MK_IDEKER_BNET Make the Bayes net in the PSB'00 paper by Ideker, Thorsson and Karp. +% +% BNET = MK_IDEKER_BNET uses the boolean functions specified in the paper +% "Discovery of regulatory interactions through perturbation: inference and experimental design", +% Pacific Symp. on Biocomputing, 2000. +% +% BNET = MK_IDEKER_BNET('root') uses the above boolean functions, but puts a uniform +% distribution on the root nodes. +% +% BNET = MK_IDEKER_BNET('cpt', p) uses random parameters drawn from a Dirichlet(p,p,...) +% distribution. If p << 1, this is nearly deterministic; if p >> 1, this is nearly uniform. +% +% BNET = MK_IDEKER_BNET('bool') makes each CPT a random boolean function. +% +% BNET = MK_IDEKER_BNET('orig') is the same as MK_IDEKER_BNET. + + +if nargin == 0 + CPD_type = 'orig'; +end + +n = 4; +dag = zeros(n); +dag(1,3)=1; +dag(2,[3 4])=1; +dag(3,4)=1; +ns = 2*ones(1,n); +bnet = mk_bnet(dag, ns); + +switch CPD_type + case 'orig', + bnet.CPD{1} = tabular_CPD(bnet, 1, [0 1]); + bnet.CPD{2} = tabular_CPD(bnet, 2, [0 1]); + bnet.CPD{3} = boolean_CPD(bnet, 3, 'inline', inline('x(1) & x(2)')); + bnet.CPD{4} = boolean_CPD(bnet, 4, 'inline', inline('x(1) & ~x(2)')); + case 'root', + bnet.CPD{1} = tabular_CPD(bnet, 1, [0.5 0.5]); + bnet.CPD{2} = tabular_CPD(bnet, 2, [0.5 0.5]); + bnet.CPD{3} = boolean_CPD(bnet, 3, 'inline', inline('x(1) & x(2)')); + bnet.CPD{4} = boolean_CPD(bnet, 4, 'inline', inline('x(1) & ~x(2)')); + case 'bool', + for i=1:n + bnet.CPD{i} = boolean_CPD(bnet, i, 'rnd'); + end + case 'cpt', + for i=1:n + bnet.CPD{i} = tabular_CPD(bnet, i, p); + end + otherwise, + error(['unknown type ' CPD_type]); +end diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_incinerator_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_incinerator_bnet.m new file mode 100644 index 00000000..1583ad17 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_incinerator_bnet.m @@ -0,0 +1,61 @@ +function bnet = mk_incinerator_bnet(ns) +% MK_INCINERATOR_BNET The waste incinerator emissions example from Cowell et al p145 +% function bnet = mk_incinerator_bnet(ns) +% +% If ns is omitted, we use the scalars and binary nodes and the original params. +% Otherwise, we use random params of the desired size. +% +% Lauritzen, "Propogation of Probabilities, Means and Variances in Mixed Graphical Association Models", +% JASA 87(420): 1098--1108 +% This example is reprinted on p145 of "Probabilistic Networks and Expert Systems", +% Cowell, Dawid, Lauritzen and Spiegelhalter, 1999, Springer. +% For a picture, see http://www.cs.berkeley.edu/~murphyk/Bayes/usage.html#cg_model + +% node numbers +F = 1; W = 2; E = 3; B = 4; C = 5; D = 6; Min = 7; Mout = 8; L = 9; +names = {'F', 'W', 'E', 'B', 'C', 'D', 'Min', 'Mout', 'L'}; +n = 9; +dnodes = [F W B]; +cnodes = mysetdiff(1:n, dnodes); + +% node sizes - all cts nodes are scalar, all discrete nodes are binary +if nargin < 1 + ns = ones(1, n); + ns(dnodes) = 2; + rnd = 0; +else + rnd = 1; +end + +% topology (p 1099, fig 1) +dag = zeros(n); +dag(F,E)=1; +dag(W,[E Min D]) = 1; +dag(E,D)=1; +dag(B,[C D])=1; +dag(D,[L Mout])=1; +dag(Min,Mout)=1; + +% params (p 1102) +bnet = mk_bnet(dag, ns, 'discrete', dnodes, 'names', names); + +if rnd + for i=dnodes(:)' + bnet.CPD{i} = tabular_CPD(bnet, i); + end + for i=cnodes(:)' + bnet.CPD{i} = gaussian_CPD(bnet, i); + end +else + bnet.CPD{B} = tabular_CPD(bnet, B, 'CPT', [0.85 0.15]); % 1=stable, 2=unstable + bnet.CPD{F} = tabular_CPD(bnet, F, 'CPT', [0.95 0.05]); % 1=intact, 2=defect + bnet.CPD{W} = tabular_CPD(bnet, W, 'CPT', [2/7 5/7]); % 1=industrial, 2=household + bnet.CPD{E} = gaussian_CPD(bnet, E, 'mean', [-3.9 -0.4 -3.2 -0.5], ... + 'cov', [0.00002 0.0001 0.00002 0.0001]); + bnet.CPD{D} = gaussian_CPD(bnet, D, 'mean', [6.5 6.0 7.5 7.0], ... + 'cov', [0.03 0.04 0.1 0.1], 'weights', [1 1 1 1]); + bnet.CPD{C} = gaussian_CPD(bnet, C, 'mean', [-2 -1], 'cov', [0.1 0.3]); + bnet.CPD{L} = gaussian_CPD(bnet, L, 'mean', 3, 'cov', 0.25, 'weights', -0.5); + bnet.CPD{Min} = gaussian_CPD(bnet, Min, 'mean', [0.5 -0.5], 'cov', [0.01 0.005]); + bnet.CPD{Mout} = gaussian_CPD(bnet, Mout, 'mean', 0, 'cov', 0.002, 'weights', [1 1]); +end diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_markov_chain_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_markov_chain_bnet.m new file mode 100644 index 00000000..a911ece5 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_markov_chain_bnet.m @@ -0,0 +1,9 @@ +function bnet = mk_markov_chain_bnet(N, Q) + +dag = zeros(N); +dag(1,2)=1; dag(2,3)=1; +ns = Q*ones(1,N); +bnet = mk_bnet(dag, ns); +for i=1:N + bnet.CPD{i} = tabular_CPD(bnet, i); +end diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_minimal_qmr_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_minimal_qmr_bnet.m new file mode 100644 index 00000000..99ad6e24 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_minimal_qmr_bnet.m @@ -0,0 +1,82 @@ +function [bnet, vals] = mk_minimal_qmr_bnet(G, inhibit, leak, prior, pos, neg, pos_only) +% MK_MINIMAL_QMR_BNET Make a QMR model which only contains the observed findings +% [bnet, vals] = mk_minimal_qmr_bnet(G, inhibit, prior, leak, pos, neg) +% +% Input: +% G(i,j) = 1 iff there is an arc from disease i to finding j +% inhibit(i,j) = inhibition probability on i->j arc +% leak(j) = inhibition prob. on leak->j arc +% prior(i) = prob. disease i is on +% pos = list of leaves that have positive observations +% neg = list of leaves that have negative observations +% pos_only = 1 means only include positively observed leaves in the model - the negative +% ones are absorbed into the prior terms +% +% Output: +% bnet +% vals is their value + +if pos_only + obs = pos; +else + obs = myunion(pos, neg); +end +Nfindings = length(obs); +[Ndiseases maxNfindings] = size(inhibit); +N = Ndiseases + Nfindings; +finding_node = Ndiseases+1:N; + +% j = finding_node(i) means the i'th finding node is the j'th node in the bnet +% k = obs(i) means the i'th observed (positive) finding is the k'th finding overall +% If all findings are observed, and posonly = 0, we have i = obs(i) for all i. + +%dag = sparse(N, N); +dag = zeros(N, N); +dag(1:Ndiseases, Ndiseases+1:N) = G(:,obs); + +ns = 2*ones(1,N); +bnet = mk_bnet(dag, ns, 'observed', finding_node); + +CPT = cell(1, Ndiseases); +for d=1:Ndiseases + CPT{d} = [1-prior(d) prior(d)]; +end + +if pos_only + % Fold in the negative evidence into the prior + for i=1:length(neg) + n = neg(i); + ps = parents(G,n); + for pi=1:length(ps) + p = ps(pi); + q = inhibit(p,n); + CPT{p} = CPT{p} .* [1 q]; + end + % Arbitrarily attach the leak term to the first parent + p = ps(1); + q = leak(n); + CPT{p} = CPT{p} .* [q q]; + end +end + +for d=1:Ndiseases + bnet.CPD{d} = tabular_CPD(bnet, d, CPT{d}'); +end + +for i=1:Nfindings + fnode = finding_node(i); + fid = obs(i); + ps = parents(G, fid); + bnet.CPD{fnode} = noisyor_CPD(bnet, fnode, leak(fid), inhibit(ps, fid)); +end + +obs_nodes = finding_node; +vals = sparse(1, maxNfindings); +vals(pos) = 2; +vals(neg) = 1; +vals = full(vals(obs)); + + + + + diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_qmr_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_qmr_bnet.m new file mode 100644 index 00000000..1532ae4c --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_qmr_bnet.m @@ -0,0 +1,41 @@ +function bnet = mk_qmr_bnet(G, inhibit, leak, prior, tabular_findings, onodes) +% MK_QMR_BNET Make a QMR model +% bnet = mk_qmr_bnet(G, inhibit, leak, prior) +% +% G(i,j) = 1 iff there is an arc from disease i to finding j +% inhibit(i,j) = inhibition probability on i->j arc +% leak(j) = inhibition prob. on leak->j arc +% prior(i) = prob. disease i is on +% tabular_findings = 1 means multinomial leaves (ignores leak/inhibit params) +% = 0 means noisy-OR leaves (default = 0) + +if nargin < 5, tabular_findings = 0; end + +[Ndiseases Nfindings] = size(inhibit); +N = Ndiseases + Nfindings; +finding_node = Ndiseases+1:N; +ns = 2*ones(1,N); +dag = zeros(N,N); +dag(1:Ndiseases, finding_node) = G; +if nargin < 6, onodes = finding_node; end +bnet = mk_bnet(dag, ns, 'observed', onodes); + +for d=1:Ndiseases + CPT = [1-prior(d) prior(d)]; + bnet.CPD{d} = tabular_CPD(bnet, d, CPT'); +end + +for i=1:Nfindings + fnode = finding_node(i); + ps = parents(G, i); + if tabular_findings + bnet.CPD{fnode} = tabular_CPD(bnet, fnode); + else + bnet.CPD{fnode} = noisyor_CPD(bnet, fnode, leak(i), inhibit(ps, i)); + end +end + + + + + diff --git a/sourcecodes/bnt-master/BNT/examples/static/Models/mk_vstruct_bnet.m b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_vstruct_bnet.m new file mode 100644 index 00000000..a37a4548 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/Models/mk_vstruct_bnet.m @@ -0,0 +1,16 @@ +function oracle = mk_vstruct_bnet() +% MK_VSTRUCT_BNET Make a simple V-structured 3-node noisy-AND Bayes net +% oracle = mk_vstruct_bnet() + +N = 3; +dag = zeros(N); +A = 1; B = 2; C = 3; +dag(A,C)=1; +dag(B,C)=1; +ns = 2*ones(1,N); + +oracle = mk_bnet(dag, ns); +oracle.CPD{1} = tabular_CPD(oracle, 1, [0.5 0.5]); +oracle.CPD{2} = tabular_CPD(oracle, 2, [0.5 0.5]); +pnoise = 0.1; % degree of noise +oracle.CPD{3} = boolean_CPD(oracle, 3, 'named', 'all', pnoise); |
