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