comparison toolboxes/distance_learning/mlr/mlr_plot.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
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), plot(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 = kernelCenter(X' * W * X);
56 else
57 % A = zeros(size(X,1));
58 A = 0;
59 if size(W,3) == 1
60 for i = 1:size(X,3)
61 A = A + X(:,:,i)' * bsxfun(@times, W(:,i), X(:,:,i));
62 end
63 else
64 if size(W,1) == size(W,2)
65 for i = 1:size(W,1)
66 for j = i:size(W,2)
67 A = A + (X(:,:,i) + X(:,:,j)') * bsxfun(@times, squeeze(W(i,j,:)), X(:,:,i) + X(:,:,j));
68 end
69 end
70
71 else
72 for i = 1:size(X,3)
73 A = A + X(:,:,i)' * W(:,:,i) * X(:,:,i);
74 end
75 end
76 end
77 end
78 [v,d] = eigs(A, 3);
79 X2 = d.^0.5 * v';
80 hold on;
81 for y = 1:max(Y)
82 z = Y == y;
83 scatter3(X2(1, z), X2(2, z), X2(3,z), CODES{y});
84 end
85
86 axis equal;