-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_LRR_AGR_subclass.m
87 lines (75 loc) · 2.21 KB
/
demo_LRR_AGR_subclass.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
% The code is written by Jie Wen,
% if you have any problems, please don't hesitate to contact me: wenjie@hrbeu.edu.cn
% If you find the code is useful, please cite the following reference:
% Jie Wen , Xiaozhao Fang, Yong Xu, Chunwei Tian, Lunke Fei,
% Low-Rank Representation with Adaptive Graph Regularization [J],
% Neural Networks, 2018.
% homepage: https://sites.google.com/view/jerry-wen-hit/home
clear all
clc
clear memory;
% % name = 'YaleB_32x32';
% % selected_class = 8;
% % lambda1 = 1e-3;
% % lambda2 = 1e-1;
% % lambda3 = 2e-1;
% name = 'YaleB_32x32';
% selected_class = 32;
% lambda1 = 1e-4;
% lambda2 = 1e-2;
% lambda3 = 1e-1;
% % name = 'COIL20';
% % selected_class = 14;
% % lambda1 = 1e-4;
% % lambda2 = 1e-3;
% % lambda3 = 2e-2;
name = 'test1484_0409';
selected_class = 10;
lambda1 = 1e-4;
lambda2 = 1e-2;
lambda3 = 1e-1;
load(name)
fea = double(fea);
nnClass = length(unique(gnd)); % The number of classes
select_sample = [];
select_gnd = [];
for i = 1:selected_class
idx = find(gnd == i);
idx_sample = fea(idx,:);
select_sample = [select_sample;idx_sample];
select_gnd = [select_gnd;gnd(idx)];
end
fea = select_sample';
fea = fea./repmat(sqrt(sum(fea.^2)),[size(fea,1) 1]);
gnd = select_gnd;
c = selected_class;
X = fea;
clear fea select_gnd select_sample idx
[m,n] = size(X);
% ---------- initilization for Z and F -------- %
options = [];
options.NeighborMode = 'KNN';
options.k = 10;
options.WeightMode = 'Binary'; % Binary HeatKernel
Z = constructW(X',options);
Z = full(Z);
Z1 = Z-diag(diag(Z));
Z = (Z1+Z1')/2;
DZ= diag(sum(Z));
LZ = DZ - Z;
[F_ini, ~, evs]=eig1(LZ, c, 0);
Z_ini = Z;
clear LZ DZ Z fea Z1
max_iter= 80;
Ctg = inv(X'*X+2*eye(size(X,2)));
%这里得到F预测,但是并没有这个而是对Z进行的Ncut
[Z,S,U,F,E] = LRR_AGR(X,F_ini,Z_ini,c,lambda1,lambda2,lambda3,max_iter,Ctg);
addpath('Ncut_9');
Z_out = Z;
A = Z_out;
A = A - diag(diag(A));
A = (A+A')/2;
[NcutDiscrete,NcutEigenvectors,NcutEigenvalues] = ncutW(A,c);
%result_label 是Ncut的 结果
[value,result_label] = max(NcutDiscrete,[],2);
result = ClusteringMeasure(gnd, result_label) %result = [ACC MIhat Purity];