Daniel@0: N = 4; Daniel@0: dag = zeros(N,N); Daniel@0: %C = 1; S = 2; R = 3; W = 4; Daniel@0: C = 4; S = 2; R = 3; W = 1; % arbitrary order Daniel@0: dag(C,[R S]) = 1; Daniel@0: dag(R,W) = 1; Daniel@0: dag(S,W)=1; Daniel@0: Daniel@0: false = 1; true = 2; Daniel@0: ns = 2*ones(1,N); % binary nodes Daniel@0: Daniel@0: bnet = mk_bnet(dag, ns); Daniel@0: bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5]); Daniel@0: bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8]); Daniel@0: bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1]); Daniel@0: bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99]); Daniel@0: Daniel@0: seed = 0; Daniel@0: rand('state', seed); Daniel@0: randn('state', seed); Daniel@0: ncases = 100; Daniel@0: data = zeros(N, ncases); Daniel@0: for m=1:ncases Daniel@0: data(:,m) = cell2num(sample_bnet(bnet)); Daniel@0: end Daniel@0: Daniel@0: order = [C S R W]; Daniel@0: max_fan_in = 2; Daniel@0: Daniel@0: %dag2 = learn_struct_K2(data, ns, order, 'max_fan_in', max_fan_in, 'verbose', 'yes'); Daniel@0: Daniel@0: sz = 5:5:50; Daniel@0: for i=1:length(sz) Daniel@0: dag2 = learn_struct_K2(data(:,1:sz(i)), ns, order, 'max_fan_in', max_fan_in); Daniel@0: correct(i) = isequal(dag, dag2); Daniel@0: end Daniel@0: correct Daniel@0: Daniel@0: for i=1:length(sz) Daniel@0: dag3 = learn_struct_K2(data(:,1:sz(i)), ns, order, 'max_fan_in', max_fan_in, 'scoring_fn', 'bic', 'params', []); Daniel@0: correct(i) = isequal(dag, dag3); Daniel@0: end Daniel@0: correct Daniel@0: Daniel@0: