Mercurial > hg > camir-aes2014
comparison toolboxes/distance_learning/mlr/mlr_plot.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function mlr_plot(X, Y, W, D) | |
2 | |
3 [d, n] = size(X); | |
4 %%% | |
5 % Color-coding | |
6 CODES = { 'b.', 'r.', 'g.', 'c.', 'k.', 'm.', 'y.', ... | |
7 'b+', 'r+', 'g+', 'c+', 'k+', 'm+', 'y+', ... | |
8 'b^', 'r^', 'g^', 'c^', 'k^', 'm^', 'y^', ... | |
9 'bx', 'rx', 'gx', 'cx', 'kx', 'mx', 'yx', ... | |
10 'bo', 'ro', 'go', 'co', 'ko', 'mo', 'yo'}; | |
11 | |
12 %%% | |
13 % First, PCA-plot of X | |
14 | |
15 figure; | |
16 | |
17 z = sum(X,3); | |
18 subplot(3,2,[1 3]), pcaplot(z, eye(d), Y, CODES), title('Native'); | |
19 subplot(3,2,[2 4]), pcaplot(X, W, Y, CODES), title('Learned'); | |
20 | |
21 [vecs, vals] = eig(z * z'); | |
22 subplot(3,2,5), bar(sort(real(diag(vals)), 'descend')), title('X*X'' spectrum'), axis tight; | |
23 | |
24 if size(X,3) == 1 | |
25 [vecs, vals] = eig(W); | |
26 vals = real(diag(vals)); | |
27 else | |
28 if size(W,3) == 1 | |
29 vals = real(W(:)); | |
30 else | |
31 vals = []; | |
32 for i = 1:size(W,3) | |
33 [vecs, vals2] = eig(W(:,:,i)); | |
34 vals = [vals ; real(diag(vals2))]; | |
35 end | |
36 end | |
37 end | |
38 subplot(3,2,6), bar(sort(vals, 'descend')), title('W spectrum'), axis tight; | |
39 | |
40 if nargin < 4 | |
41 return; | |
42 end | |
43 | |
44 %%% | |
45 % Now show some diagnostics | |
46 | |
47 figure; | |
48 subplot(2,1,1), semilogy(D.f), title('Objective'); | |
49 subplot(2,1,2), barh([D.time_SO, D.time_solver D.time_total]), ... | |
50 title('Time% in SO/solver/total'); | |
51 | |
52 | |
53 function pcaplot(X, W, Y, CODES) | |
54 if size(X,3) == 1 | |
55 A = X' * W * X; | |
56 else | |
57 A = 0; | |
58 if size(W,3) == 1 | |
59 for i = 1:size(X,3) | |
60 A = A + X(:,:,i)' * bsxfun(@times, W(:,i), X(:,:,i)); | |
61 end | |
62 else | |
63 for i = 1:size(X,3) | |
64 A = A + X(:,:,i)' * W(:,:,i) * X(:,:,i); | |
65 end | |
66 end | |
67 end | |
68 [v,d] = eigs(A, 3); | |
69 X2 = d.^0.5 * v'; | |
70 hold on; | |
71 for y = 1:max(Y) | |
72 z = Y == y; | |
73 scatter3(X2(1, z), X2(2, z), X2(3,z), CODES{y}); | |
74 end | |
75 | |
76 axis equal; |