-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_KDMLMJ.m
39 lines (30 loc) · 1.12 KB
/
demo_KDMLMJ.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
load('data/rings.mat');
fprintf('Demo of KDMLMJ on the ring data set\n');
fprintf('\n----------------------------------------------\n');
% setup the parameters
params = struct();
params.knn = 5; % number of neighbors
params.k1 = 5;
params.k2 = 5;
params.dim = 2; % the desired number of features
% Learn a simple linear transformation with DMLMJ
L1 = DMLMJ(xTr, yTr, params);
% Apply the kernel trick with KDMLMJ
params.kernel = 1; % RBF kernel is used
[L2, params] = DMLMJ(xTr, yTr, params);
X = kernelmatrix('rbf', xTr, xTr, params.sigma);
% Plot data in the transformed spaces
% Euclidean
subplot(1,3, 1)
gscatter(xTr(1,:), xTr(2,:), yTr, 'rb','o*'), legend('off'), ...
axis square, set(gca,'Box','on'), title('Euclidean')...
xTrKer = L2' * X;
% KDMLMJ
subplot(1,3, 2)
gscatter(xTrKer(1,:), xTrKer(2,:), yTr, 'rb','o*'), legend('off'), ...
axis square, set(gca,'Box','on'), title('KDMLMJ')......
xTrLin = L1' * xTr;
% DMLMJ
subplot(1,3, 3)
gscatter(xTrLin(1,:), xTrLin(2,:), yTr, 'rb','o*'), legend('off'), ...
axis square, set(gca,'Box','on'), title('DMLMJ')......