Attachment 'U02_test_isomap_lle.m'

Download

   1 function U02_test_isomap_lle(method, n_rule)
   2 %U02_TEST_ISOMAP_LLE          Test for Isomap and LLE.
   3 %
   4 %synopsis
   5 %  U02_test_isomap_lle(method, n_rule)
   6 %
   7 %arguments
   8 %  method: Function which should be tested. Has to be 'isomap' or 'lle'.
   9 %  n_rule: Rule to build the graph, has to be 'knn' or 'eps-ball'.
  10 %
  11 %usage
  12 %  U02_test_isomap_lle('isomap', 'knn')
  13 %  U02_test_isomap_lle('isomap', 'eps-ball')
  14 %  U02_test_isomap_lle('lle', 'knn')
  15 %  U02_test_isomap_lle('lle', 'eps-ball')
  16 %
  17 %author
  18 %  buenau@cs.tu-berlin.de, saputra@cs.tu-berlin.de
  19 
  20 if strcmp(method, 'isomap') == 0 & strcmp(method, 'lle') == 0
  21     fprintf('Unknown method: %s, has to be ''isomap'' or ''lle''\n', method);
  22     return;
  23 end
  24 
  25 if strcmp(n_rule, 'knn') == 0 & strcmp(n_rule, 'eps-ball') == 0
  26     fprintf('Unknown n_rule: %s, has to be ''knn'' or ''eps-ball''\n', method);
  27     return;
  28 end
  29 
  30 n = 500;
  31 
  32 % Generate data with structure in the first two dimensions 
  33 % + eig noise dimensions (relatively small variance).
  34 Xt = 10*rand(2,n);
  35 X = [ Xt; 0.5*randn(8,n) ];
  36 
  37 % Rotate data randomly.
  38 X = randrot(10)*X;
  39 
  40 if strcmp(n_rule, 'knn')
  41     param = 30;
  42 else
  43     param = 4;
  44 end
  45 
  46 % check which method should be used (isomap or lle)
  47 if strcmp(method, 'isomap')
  48     Xp = Isomap(X, 2, n_rule, param);
  49 else
  50     Xp = LLE(X, 2, n_rule, param);
  51 end
  52 
  53 % Plot true 2D manifold embedded in ten dimensions.
  54 clf;
  55 subplot(1,3,1);
  56 scatter(Xt(1,:), Xt(2,:));
  57 title('True 2D manifold');
  58 axis image;
  59 xlabel('x_1');
  60 ylabel('x_2');
  61 set(gca, 'XLim', [-1 11]);
  62 set(gca, 'YLim', [-1 11]);
  63 set(gca, 'XTick', [], 'YTick', []);
  64 
  65 % Plot 2D embedding found by isomap/lle with colors according to the 
  66 % first manifold coordinate.
  67 subplot(1,3,2);
  68 scatter(Xp(1,:), Xp(2,:), [], Xt(1,:));
  69 title('Embedding colored according to x_1');
  70 axis image;
  71 set(gca, 'XTick', [], 'YTick', []);
  72 
  73 % Plot 2D embedding found by isomap/lle with colors according to the 
  74 % second manifold coordinate.
  75 subplot(1,3,3);
  76 scatter(Xp(1,:), Xp(2,:), [], Xt(2,:));
  77 title('Embedding colored according to x_2');
  78 axis image;
  79 set(gca, 'XTick', [], 'YTick', []);
  80 
  81 function [ R, M ] = randrot(d)
  82 %RANDROT        Generate random orthogonal matrix. 
  83 %
  84 %usage
  85 %  [R,M] = randrot(d)
  86 %
  87 %author
  88 %  buenau@cs.tu-berlin.de
  89 
  90 M = 100*(rand(d,d)-0.5);
  91 M = 0.5*(M-M');
  92 R = expm(M);

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.