Attachment 'Aufgabe5.m'
Download 1 function Aufgabe5
2 %Aufgabe5 - plot some statistics of USPS dataset: class means, std deviations and outliers.
3 %
4 %usage
5 % Aufgabe5
6 %
7 %description
8 % Aufgabe5 loads the USPS dataset (from usps.mat) and plots
9 % 1. the class means;
10 % 2. the standard deviation of classes 1, 2 and 7; and
11 % 3. the three datapoints of classes 1, 2, and 7 which are most distant from
12 % the respective class means.
13 %
14 %author
15 % buenau@cs.tu-berlin.de
16
17 load usps.mat;
18
19 n = size(data_patterns, 2);
20
21 % Plot class means.
22 colormap gray;
23 for i=1:10
24 subplot(2, 5, i);
25 imagesc(reshape(mean(data_patterns(:,find(data_labels(i,:) == 1)), 2), [16 16])');
26 axis off;
27 title(sprintf('Mean of class %d', i-1));
28 end
29
30 figure;
31 ci = [ 2 3 8 ];
32
33 % Plot standard deviations of classes 1, 2, 7.
34 for i=1:length(ci)
35 subplot(3,1,i);
36 bar3(reshape(std(data_patterns(:,find(data_labels(ci(i),:) == 1)), [], 2), [16 16])'); axis off;
37 title(sprintf('Stddev of class %d', ci(i)-1));
38 end
39
40 % Find and plot outliers of classes 1, 2, 7.
41
42 % Compute squared distance matrix.
43 xx = sum( data_patterns .^ 2, 1);
44 D = repmat(xx, [n 1]) -2*data_patterns'*data_patterns + repmat(xx', [1 n]);
45
46 figure;
47 colormap gray;
48
49 for i=1:length(ci)
50 c_ii = find(data_labels(ci(i),:) == 1);
51 m = mean(data_patterns(:,c_ii), 2);
52 dist = sum( ( data_patterns(:,c_ii) - repmat(m, [1 length(c_ii)]) ) .^ 2, 1 );
53 [foo, s_ii ] = sort(-dist);
54
55 for j=1:3
56 subplot(3, 3, sub2ind([3 3], i, j));
57 imagesc(reshape(data_patterns(:,c_ii(s_ii(j))), [16 16])');
58 if j == 1, title(sprintf('Outliers of class %d', ci(i)-1)); end
59 end
60 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.