Attachment 'sheet06.m'
Download 1 function sheet06
2
3 % Generate some data
4 N = 100;
5 M1 = [1; 2];
6 M2 = [-5; 7];
7 X = [randn(2, N) + repmat(M1, 1, N), ...
8 randn(2, N) + repmat(M2, 1, N)];
9 Y = [ones(1, N), -ones(1, N)];
10
11 % Show data
12 subplot(3,1,1);
13 plotdata(X, Y);
14
15 % Compute fda direction and another one and show
16 % the projected data
17 W = fda(X, Y)
18 W1 = [1; 0];
19
20 hold on;
21 plotdata(project(X, W), Y);
22 plotdata(project(X, W1), Y);
23 hold off;
24
25 % Histograms for the fda direction
26 subplot(3,1,2);
27 show_projected_data(W'*X, Y);
28
29 % Histograms for the other direction
30 subplot(3,1,3);
31 show_projected_data(W1'*X, Y);
32
33 % Plot two classes.
34 function plotdata(X, Y)
35 P = (Y == 1);
36 N = (Y == -1);
37
38 plot(X(1, P), X(2, P), 'r+', X(1, N), X(2, N), 'bo');
39
40 axis equal
41 grid on
42
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 % Your solutions below
45 %
46
47 % 1. Return scatter matrix S = (X - M)(X - M)'
48 function S = scatter(X, M)
49 % ...
50
51 % 2. Compute FDA direction.
52 function W = fda(X, Y)
53 % ...
54
55 % 3. Project X to subspace spanned by W.
56 function X = project(X, W)
57 % ...
58
59 % 4. Plot histograms for both classes of a
60 % one-dimensional data set X.
61 function show_projected_data(X, Y)
62 % ...
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.