Attachment 'U02_test_pca.m'

Download

   1 function U02_test_pca
   2 %U02_TEST_PCA           Test PCA.
   3 %
   4 %Your PCA function must *not* center the data!!!
   5 %
   6 %usage
   7 %  U02_test_pca
   8 %
   9 %author
  10 %  saputra@cs.tu-berlin.de
  11 
  12 % filename of script to test
  13 filename = 'PCA.m';
  14 
  15 % data
  16 X = [
  17    0.620350139445525   0.135175444758437   1.183719539936857  -0.716428623725855   0.106814075934588   2.212554078989681  -1.680542777522645   0.008934115676568
  18    5.079127388759098  -0.556160040161770  -0.061718647133300  -2.622237558015624   7.392864872075875   6.034103024384587  -2.294136536423504   3.347799563349179
  19    0.634890923594887  -0.069520005020221  -0.007714830891663  -0.327779694751953   0.924108109009484   0.754262878048073  -0.286767067052938   0.418474945418647 ];
  20 
  21 m = 2;
  22 
  23 % correct results
  24 correct_Z = [
  25    0.000000000000001  -0.000000000000000  -0.000000000000000  -0.000000000000000   0.000000000000001   0.000000000000000  -0.000000000000000   0.000000000000000
  26    0.241451624679969  -0.226701139502802  -1.177529274921587   0.265958918169822   1.136435832509665  -1.168077599461355   1.271697872161680   0.553510036896045 ];
  27 
  28 correct_U = [
  29   -0.166669742451379  -0.986012777275828  -0.000000000000000
  30   -0.978398665047805   0.165382698152069  -0.124034734589208
  31   -0.122299833130975   0.020672837269008   0.992277876713668 ];
  32 
  33 correct_D = 1.0e+02 * [1.466203213045900   0.061464821519444   0.000000000000000];
  34 
  35 % run test
  36 if exist(filename, 'file')
  37     fprintf(['Testing ' filename  '...\n']);
  38     [Z, U, D] = PCA(X, m);
  39     assert_equal(size(correct_Z), size(Z), 'Size of matrix Z does not match.');
  40     assert_equal(size(correct_U), size(U), 'Size of matrix U does not match.');
  41     assert_equal(size(correct_D), size(D), 'Size of vector D does not match (is D maybe a column instead of a row vector?)');
  42     assert_equal(correct_Z, Z, 'Matrix Z isn''t correct.', 'Matrix Z is correct.');
  43     assert_equal(correct_U, U, 'Matrix U isn''t correct.', 'Matrix U is correct.');
  44     assert_equal(correct_D, D, 'Matrix D isn''t correct.', 'Matrix D is correct.');
  45 else
  46     fprintf([filename 'not found.\n']);
  47 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.