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.You are not allowed to attach a file to this page.