diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/examples/static/lw1.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/static/lw1.m')
| -rw-r--r-- | sourcecodes/bnt-master/BNT/examples/static/lw1.m | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/examples/static/lw1.m b/sourcecodes/bnt-master/BNT/examples/static/lw1.m new file mode 100644 index 00000000..a6a35577 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/examples/static/lw1.m @@ -0,0 +1,51 @@ +% Evaluate effectiveness of likelihood weighting on the lawn sprinkler example + +N = 4; +dag = zeros(N,N); +C = 1; R = 2; S = 3; W = 4; +dag(C,[R S]) = 1; +dag(R,W) = 1; +dag(S,W)=1; + +false = 1; true = 2; +ns = 2*ones(1,N); % binary nodes + +bnet = mk_bnet(dag, ns); +bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5]); +bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8]); +bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1]); +bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99]); + + +clear engine; +engine{1} = jtree_inf_engine(bnet); +engine{2} = likelihood_weighting_inf_engine(bnet); + +nengines = length(engine); +m = cell(1, nengines); +ll = zeros(1, nengines); + +evidence = cell(1,N); +%evidence{C} = true; % evidence at the top is the easiest +evidence{W} = true; % evidence at the bottom is the hardets + +query = [R]; + +i=1; +engine{i} = enter_evidence(engine{i}, evidence); +exact_m = marginal_nodes(engine{i}, query); + +i=2; +samples = 100:100:500; +err = zeros(1, length(samples)); +for j=1:length(samples) + nsamples = samples(j); + engine{i} = enter_evidence(engine{i}, evidence, nsamples); + approx_m = marginal_nodes(engine{i}, query); + a1=approxeq(approx_m.T,exact_m.T,1e-1); + a2=approxeq(approx_m.T,exact_m.T,1e-2); + a3=approxeq(approx_m.T,exact_m.T,1e-3); + e = sum(abs(approx_m.T(:) - exact_m.T(:))); + fprintf('%d samples, 1dp %d, 2dp %d, 3dp %d, err %f\n', nsamples, a1, a2, a3, e); + err(j) = e; +end |
