-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_RLDA_toy_three_ring_subspace.m
126 lines (104 loc) · 2.93 KB
/
test_RLDA_toy_three_ring_subspace.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
clc;
clear all;
close all;
folder_now = pwd;
addpath([folder_now,'\function']);
addpath([folder_now,'\feature selection']);
savePath=[folder_now '\synthetic'];
newdata = 1;
datatype = 2; % 1: three-Gaussian data, 2: three-ring data
interval = [0.5 0.75 0.9;0.45,0.8,0.9;0.4,0.6,0.9];
idx=1;
m=2;
if newdata == 1
clearvars -except datatype savePath m;
if datatype == 1
[X, Y, n1, n2, n3] = threegaussian_dim_gen(300, 0.05, 10, 0.5);
else
[X, Y] = three_ring_dim_gen;
end;
save ([savePath '\d3.mat'],'X', 'Y');
c = 2;
else
load([savePath '\d3.mat'], 'X', 'Y');
end;
% hl=figure('name','data');
% set(gca, 'fontsize',15);
% %plot(X(:,1),X(:,2),'.k'); hold on;
% plot3(X(Y==1,1),X(Y==1,2),X(Y==1,3),'.r','MarkerSize',15); hold on;
% plot3(X(Y==2,1),X(Y==2,2),X(Y==2,3),'.b','MarkerSize',15); hold on;
% grid on;
% axis equal;
%pcan
% [PW, la, A, evs] = PCAN(X', c);
% figure('name','Learned graph by PCAN');
% imshow(A,[]); colormap jet; colorbar;
hl=figure('name','Original Data');
set(gca, 'fontsize',15);
%plot(X(:,1),X(:,2),'.k'); hold on;
plot(X(Y==1,1),X(Y==1,2),'.r','MarkerSize',15); hold on;
plot(X(Y==2,1),X(Y==2,2),'.b','MarkerSize',15); hold on;
plot(X(Y==3,1),X(Y==3,2),'.g','MarkerSize',15); hold on;
minx = 1.5*min(X(:,1)); maxx = 1.5*max(X(:,1));
miny = 1.1*min(X(:,2)); maxy = 1.1*max(X(:,2));
saveas(hl,[savePath '\comp_3ring.jpg']);
%PCAN
% set(gca, 'fontsize',15);
% if abs(PW(1))>abs(PW(2))
% h1 = plot([minx, maxx],[PW(2)/PW(1)*minx, PW(2)/PW(1)*maxx],'b','LineWidth',2,'MarkerSize',15); hold on;
% else
% h1 = plot([PW(1)/PW(2)*miny,PW(1)/PW(2)*maxy], [miny, maxy],'b','LineWidth',2,'MarkerSize',15); hold on;
% end;
% axis equal;
cm = colormap(jet(c));
% pca
num = size(X,1);
W = PCA(X',m);
X1 = X*W;
figure('name','Learned subspace by PCA');
plot(X1(:,1),X1(:,2),'.k'); hold on;
for i = 1:c
plot(X1(Y==i,1),X1(Y==i,2),'.', 'color', cm(i,:)); hold on;
end;
axis equal;
% lpp
W=LPP(X',m);
X2 = X*W;
figure('name','Learned subspace by LPP');
plot(X2(:,1),X2(:,2),'.k'); hold on;
for i = 1:c
plot(X2(Y==i,1),X2(Y==i,2),'.', 'color', cm(i,:)); hold on;
end;
axis equal;
% lda
W=LDA(X',Y,m);
X3 = X*W;
figure('name','Learned subspace by LDA');
plot(X3(:,1),X3(:,2),'.k'); hold on;
cm = colormap(jet(c));
for i = 1:c
plot(X3(Y==i,1),X3(Y==i,2),'.', 'color', cm(i,:)); hold on;
end;
axis equal;
% ldfs
[~,~,W]=LDFS(X',Y,m);
X4 = X*W;
figure('name','Learned subspace by LDFS');
plot(X4(:,1),X4(:,2),'.k'); hold on;
for i = 1:c
plot(X4(Y==i,1),X4(Y==i,2),'.', 'color', cm(i,:)); hold on;
end;
axis equal;
%RLDA
[rank,sw,RW,obj,S]=RLDA(X',Y,m,0.000001);
% S(logical(eye(size(S,1))))=0;
% S(logical(eye(size(S,1))))=max(max(S));
figure('name','Learned graph by RLDA');
imshow(S,[]); colormap jet; colorbar;
X5 = X*RW;
figure('name','Learned subspace by RLDA');
plot(X5(:,1),X5(:,2),'.k'); hold on;
for i = 1:c
plot(X5(Y==i,1),X5(Y==i,2),'.', 'color', cm(i,:)); hold on;
end;
axis equal;