Attachment 'U06_test_margs.m'
Download 1 function U06_test_margs
2 %U06_TEST_MARGS Test simple_marg and bp.
3 %
4 %usage
5 % U06_test_margs
6 %
7 %author
8 % buenau@cs.tu-berlin.de
9
10 % Data (kindly donated by Pascal Lehwark).
11 A=[0 1 0 0 0 0;1 0 1 1 0 0;0 1 0 0 0 0;0 1 0 0 1 1;0 0 0 1 0 0;0 0 0 1 0 0];
12 E=[0.1 0.1 0.1 0.9 0.1 0.9;0.9 0.9 0.9 0.1 0.9 0.1];
13 L=[0.2 0.7;0.7 0.2];
14
15 % Correct marginals.
16 correct_margs = [ 0.224137931034483 0.224137931034483 0.224137931034483 0.913368700265252 0.052360416241583 0.741591185472353; ...
17 0.775862068965517 0.775862068965517 0.775862068965517 0.086631299734748 0.947639583758417 0.258408814527647 ];
18
19 % Run tests.
20
21 if exist('bp.m', 'file')
22 % Test Belief Propagation.
23 fprintf('Testing bp.m ... ');
24 margs = bp(A,E,L);
25
26 if max(max(abs(margs - correct_margs))) > 1e-10
27 fprintf('failed (discrepancy > 1e-10).\n');
28 else
29 fprintf('OK.\n');
30 end
31 end
32
33 if exist('simple_marg.m', 'file')
34 % Naive summing.
35 fprintf('Testing simple_marg.m ... ');
36 margs = simple_marg(A,E,L);
37
38 if max(max(abs(margs - correct_margs))) > 1e-10
39 fprintf('failed (discrepancy > 1e-10).\n');
40 else
41 fprintf('OK.\n');
42 end
43 end
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.