Attachment 'U03_test_kmeans.m'

Download

   1 function U03_test_kmeans
   2 %U03_TEST_KMEANS           Test kmeans.
   3 %
   4 %usage
   5 %  U03_test_kmeans
   6 %
   7 %author
   8 %  saputra@cs.tu-berlin.de
   9 
  10 % filename of script to test
  11 filename = 'kmeans.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 correct_r = [ones(1, ns) 2*ones(1, ns) 3*ones(1, ns)];
  20 correct_same_cluster = (repmat(correct_r, 3*ns, 1) == repmat(correct_r', 1, 3*ns));
  21 
  22 % run test
  23 if exist(filename, 'file')
  24     fprintf(['Testing ' filename  '...\n']);
  25     [mu, r] = kmeans(X, 3);
  26     assert_equal(size(correct_r), size(r), 'Size of r does not match. Remember: r has to be a row vector!');
  27     same_cluster = (repmat(r, 3*ns, 1) == repmat(r', 1, 3*ns));
  28     num_correct_clusterings = sum(sum(triu(correct_same_cluster == same_cluster, 1)));
  29     fprintf('Pairwise correct cluster belongings: %.2f %%\n', 100*(num_correct_clusterings/11175));
  30     fprintf('Please run the test multiple times. You should nearly always get 100 %%\n');
  31 else
  32     fprintf([filename 'not found.\n']);
  33 end
  34 
  35 function [] = assert_equal(A, B, error, success)
  36 
  37 if max(max(abs(A - B))) > 1e-3
  38     fprintf(['Error: ' error '\n']);
  39     expected = A
  40     got = B
  41 else
  42     if nargin > 3
  43         fprintf(['OK: ' success '\n']);
  44     end
  45 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.
  • [get | view] (2009-04-20 10:21:37, 64.6 KB) [[attachment:ML_Praktikum_U01.pdf]]
  • [get | view] (2009-04-28 15:32:01, 71.3 KB) [[attachment:ML_Praktikum_U02.pdf]]
  • [get | view] (2009-05-18 09:22:01, 67.0 KB) [[attachment:ML_Praktikum_U03.pdf]]
  • [get | view] (2009-06-16 10:27:54, 88.5 KB) [[attachment:ML_Praktikum_U04.pdf]]
  • [get | view] (2009-07-06 08:59:00, 65.3 KB) [[attachment:ML_Praktikum_U05.pdf]]
  • [get | view] (2009-04-20 09:38:21, 48.3 KB) [[attachment:Matlab_Crash_Kurs.txt]]
  • [get | view] (2009-03-27 15:28:49, 65.9 KB) [[attachment:Praktikum_ML_Info.pdf]]
  • [get | view] (2009-04-22 16:14:23, 1.2 KB) [[attachment:U01_test_distmat.m]]
  • [get | view] (2009-04-22 16:14:28, 1.0 KB) [[attachment:U01_test_mydet.m]]
  • [get | view] (2009-04-28 15:32:56, 4053.5 KB) [[attachment:U01_usps.mat]]
  • [get | view] (2009-05-12 10:14:36, 2.2 KB) [[attachment:U02_test_isomap_lle.m]]
  • [get | view] (2009-05-12 10:14:45, 39.1 KB) [[attachment:U02_test_isomap_lle_example.png]]
  • [get | view] (2009-05-12 10:14:51, 2.0 KB) [[attachment:U02_test_pca.m]]
  • [get | view] (2009-05-13 10:04:58, 38.5 KB) [[attachment:U02_tests.zip]]
  • [get | view] (2009-05-18 07:57:34, 6.3 KB) [[attachment:U03_2gaussians.dat]]
  • [get | view] (2009-05-18 07:57:39, 15.6 KB) [[attachment:U03_5gaussians.dat]]
  • [get | view] (2009-06-05 10:12:33, 1.3 KB) [[attachment:U03_test_em_mog.m]]
  • [get | view] (2009-06-05 10:12:53, 0.8 KB) [[attachment:U03_test_function_handle_em_mog.m]]
  • [get | view] (2009-06-05 10:12:46, 0.8 KB) [[attachment:U03_test_function_handle_kmeans.m]]
  • [get | view] (2009-06-05 10:11:43, 1.3 KB) [[attachment:U03_test_kmeans.m]]
  • [get | view] (2009-06-05 10:12:02, 80.6 KB) [[attachment:U03_test_kmeans_agglo.m]]
  • [get | view] (2009-06-16 10:28:07, 1018.4 KB) [[attachment:U04_datasets.tar.gz]]
  • [get | view] (2009-07-01 11:00:45, 1.1 KB) [[attachment:U04_test_CV_krr.m]]
  • [get | view] (2009-07-15 09:23:29, 6.4 KB) [[attachment:U05_datasets.zip]]
  • [get | view] (2009-05-12 10:14:30, 0.9 KB) [[attachment:assert_equal.m]]
  • [get | view] (2009-04-28 15:33:04, 60.1 KB) [[attachment:fishbowl.mat]]
  • [get | view] (2009-04-28 15:33:13, 22.7 KB) [[attachment:flatroll.mat]]
  • [get | view] (2009-04-20 09:38:35, 0.1 KB) [[attachment:func1.m]]
  • [get | view] (2009-05-13 08:10:49, 371.6 KB) [[attachment:guide.pdf]]
  • [get | view] (2009-04-20 09:38:40, 0.2 KB) [[attachment:myprod.m]]
  • [get | view] (2009-04-28 15:33:08, 45.3 KB) [[attachment:swissroll.mat]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.