N = 4; 
dag = zeros(N,N);
dag(1,2) = 1; dag(1,3) = 1; dag(2,4) = 1; dag(3,4) = 1;
node_sizes = twos(1,N);
bnet = mk_bnet(dag, node_sizes);

for i=1:N
  bnet.bnodes{i} = mk_tabular_node(bnet, i);
end

bnet.bnodes{1}.CPT(:) = [0.5 0.5];
bnet.bnodes{2}.CPT(:) = [0.5 0.9 0.5 0.1];
bnet.bnodes{3}.CPT(:) = [0.8 0.2 0.2 0.8];
bnet.bnodes{4}.CPT(:) = [1 0.1 0.1 0.01 0 0.9 0.9 0.99];

nsamples = 30;
bnet = change_algo(bnet, 'lw');
bnet.sample.num_samples = nsamples;

obs_nodes = [4];
vals = [2];

% Use matlab
bnet = compile_params(bnet, 0);
rand('state', 0);
tic; [bnet, ll] = enter_evidence(bnet, vals, obs_nodes); t1=toc
m = marginal_nodes(bnet, 3);
p1 = m.T(2)

% Use C
tic; bnet = compile_params(bnet, 1); toc
rand('state', 0);
tic; [bnet, ll] = enter_evidence(bnet, vals, obs_nodes); t2=toc
m = marginal_nodes(bnet, 3);
p2 = m.T(2)

