annotate toolboxes/FullBNT-1.0.7/bnt/examples/static/StructLearn/k2demo1.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 N = 4;
wolffd@0 2 dag = zeros(N,N);
wolffd@0 3 %C = 1; S = 2; R = 3; W = 4;
wolffd@0 4 C = 4; S = 2; R = 3; W = 1; % arbitrary order
wolffd@0 5 dag(C,[R S]) = 1;
wolffd@0 6 dag(R,W) = 1;
wolffd@0 7 dag(S,W)=1;
wolffd@0 8
wolffd@0 9 false = 1; true = 2;
wolffd@0 10 ns = 2*ones(1,N); % binary nodes
wolffd@0 11
wolffd@0 12 bnet = mk_bnet(dag, ns);
wolffd@0 13 bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5]);
wolffd@0 14 bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8]);
wolffd@0 15 bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1]);
wolffd@0 16 bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99]);
wolffd@0 17
wolffd@0 18 seed = 0;
wolffd@0 19 rand('state', seed);
wolffd@0 20 randn('state', seed);
wolffd@0 21 ncases = 100;
wolffd@0 22 data = zeros(N, ncases);
wolffd@0 23 for m=1:ncases
wolffd@0 24 data(:,m) = cell2num(sample_bnet(bnet));
wolffd@0 25 end
wolffd@0 26
wolffd@0 27 order = [C S R W];
wolffd@0 28 max_fan_in = 2;
wolffd@0 29
wolffd@0 30 %dag2 = learn_struct_K2(data, ns, order, 'max_fan_in', max_fan_in, 'verbose', 'yes');
wolffd@0 31
wolffd@0 32 sz = 5:5:50;
wolffd@0 33 for i=1:length(sz)
wolffd@0 34 dag2 = learn_struct_K2(data(:,1:sz(i)), ns, order, 'max_fan_in', max_fan_in);
wolffd@0 35 correct(i) = isequal(dag, dag2);
wolffd@0 36 end
wolffd@0 37 correct
wolffd@0 38
wolffd@0 39 for i=1:length(sz)
wolffd@0 40 dag3 = learn_struct_K2(data(:,1:sz(i)), ns, order, 'max_fan_in', max_fan_in, 'scoring_fn', 'bic', 'params', []);
wolffd@0 41 correct(i) = isequal(dag, dag3);
wolffd@0 42 end
wolffd@0 43 correct
wolffd@0 44
wolffd@0 45