Attachment 'U03_test_em_mog.m'
Download 1 function U03_test_em_mog
2 %U03_TEST_EM_MOG Test em_mog.
3 %
4 %usage
5 % U03_test_em_mog
6 %
7 %author
8 % saputra@cs.tu-berlin.de
9
10 % filename of script to test
11 filename = 'em_mog.m';
12
13 % generate data set
14 mu_1 = [-4; 0];
15 mu_2 = [4; 0];
16 mu_3 = [0; sqrt(48)];
17 ns = 50;
18 X = [(randn(2, ns) + repmat(mu_1, 1, ns)) (randn(2, ns) + repmat(mu_2, 1, ns)) (randn(2, ns) + repmat(mu_3, 1, ns))];
19
20 % run test
21 if exist(filename, 'file')
22 fprintf(['Testing ' filename '...\n']);
23 [pi, mu, sigma] = em_mog(X, 3);
24 %[mu, sigma, pi] = em_mog(X, 3);
25 %pi=pi';
26 assert_equal([1, 3], size(pi), 'Size of pi does not match. Remember: pi has to be a row vector!');
27 assert_equal([2, 3], size(mu), 'Size of mu does not match.');
28 assert_equal([3, 1], size(sigma), 'Size of sigma does not match. Remember: sigma has to be a (k x 1) cell array!');
29
30 fprintf('If you got no error messages then the dimensions of your returned variables are OK.\n');
31 fprintf('This does not mean you function works correctly. It''s hard to check whether a result of EM is correct.\n');
32 else
33 fprintf([filename 'not found.\n']);
34 end
35
36 function [] = assert_equal(A, B, error, success)
37
38 if max(max(abs(A - B))) > 1e-3
39 fprintf(['Error: ' error '\n']);
40 expected = A
41 got = B
42 else
43 if nargin > 3
44 fprintf(['OK: ' success '\n']);
45 end
46 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.