function U06_test_margs
%U06_TEST_MARGS            Test simple_marg and bp.
%
%usage
%  U06_test_margs
%
%author
%  buenau@cs.tu-berlin.de

% Data (kindly donated by Pascal Lehwark).
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];
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];
L=[0.2 0.7;0.7 0.2]; 

% Correct marginals.
correct_margs = [   0.224137931034483   0.224137931034483   0.224137931034483   0.913368700265252   0.052360416241583   0.741591185472353; ...
                   0.775862068965517   0.775862068965517   0.775862068965517   0.086631299734748   0.947639583758417   0.258408814527647 ];

% Run tests.

if exist('bp.m', 'file') 
  % Test Belief Propagation.
  fprintf('Testing bp.m ... ');
  margs = bp(A,E,L);

  if max(max(abs(margs - correct_margs))) > 1e-10
    fprintf('failed (discrepancy > 1e-10).\n');
  else
    fprintf('OK.\n'); 
  end
end

if exist('simple_marg.m', 'file') 
  % Naive summing.
  fprintf('Testing simple_marg.m ... ');
  margs = simple_marg(A,E,L);

  if max(max(abs(margs - correct_margs))) > 1e-10
    fprintf('failed (discrepancy > 1e-10).\n');
  else
    fprintf('OK.\n'); 
  end
end
