forked from Tracesource/FIMVC-VIA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.m
101 lines (88 loc) · 4.16 KB
/
run.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
clear;
clc;
addpath(genpath('./'));
resultdir1 = 'Results/';
if (~exist('Results', 'file'))
mkdir('Results');
addpath(genpath('Results/'));
end
resultdir2 = 'aResults/';
if (~exist('aResults', 'file'))
mkdir('aResults');
addpath(genpath('aResults/'));
end
datadir='./datasets/';
dataname={'ORL_mtv'};
numdata = length(dataname); % number of the test datasets
numname = {'_Per0.1', '_Per0.2', '_Per0.3', '_Per0.4','_Per0.5', '_Per0.6', '_Per0.7', '_Per0.8', '_Per0.9'};
for idata = 1:1 :length(dataname)
ResBest = zeros(9, 8);
ResStd = zeros(9, 8);
for dataIndex = 1:1:9
datafile = [datadir, cell2mat(dataname(idata)), cell2mat(numname(dataIndex)), '.mat'];
load(datafile);
%data preparation...
gt = truelabel{1};
cls_num = length(unique(gt));
k= cls_num;
tic;
[X1, ind] = findindex(data, index);
time1 = toc;
maxAcc = 0;
TempLambda1 = [0.001 0.1 1 10 100 1000];
TempLambda2 = [k,2*k, 3*k,5*k,7*k];
ACC = zeros(length(TempLambda1),length(TempLambda2));
NMI = zeros(length(TempLambda1), length(TempLambda2));
Purity = zeros(length(TempLambda1), length(TempLambda2));
idx = 1;
for LambdaIndex1 = 1 : length(TempLambda1)
lambda1 = TempLambda1(LambdaIndex1);
for LambdaIndex2 = 1 : length(TempLambda2)
lambda2 = TempLambda2(LambdaIndex2);
disp([char(dataname(idata)), char(numname(dataIndex)), '-l1=', num2str(lambda1), '-l2=', num2str(lambda2)]);
tic;
para.c = cls_num; % K: number of clusters
para.k = lambda1; % m: number of nearest anchors
[F,V,A,Z,iter,obj] = missingalgo_qp(X1,gt,lambda1,lambda2,ind); % X,Y,lambda,d,numanchor
F = F ./ repmat(sqrt(sum(F .^ 2, 2)), 1, k);
time2 = toc;
stream = RandStream.getGlobalStream;
reset(stream);
MAXiter = 1000; % Maximum number of iterations for KMeans
REPlic = 20; % Number of replications for KMeans
tic;
for rep = 1 : 20
pY = kmeans(F, cls_num, 'maxiter', MAXiter, 'replicates', REPlic, 'emptyaction', 'singleton');
res(rep, : ) = Clustering8Measure(gt, pY);
end
time3 = toc;
runtime(idx) = time1 + time2 + time3/20;
disp(['runtime:', num2str(runtime(idx))])
idx = idx + 1;
tempResBest(dataIndex, : ) = mean(res);
tempResStd(dataIndex, : ) = std(res);
ACC(LambdaIndex1, LambdaIndex2) = tempResBest(dataIndex, 1);
NMI(LambdaIndex1, LambdaIndex2) = tempResBest(dataIndex, 2);
Purity(LambdaIndex1, LambdaIndex2) = tempResBest(dataIndex, 3);
save([resultdir1, char(dataname(idata)), char(numname(dataIndex)), '-l1=', num2str(lambda1), '-l2=', num2str(lambda2), ...
'-acc=', num2str(tempResBest(dataIndex,1)), '_result.mat'], 'tempResBest', 'tempResStd');
for tempIndex = 1 : 8
if tempResBest(dataIndex, tempIndex) > ResBest(dataIndex, tempIndex)
if tempIndex == 1
newZ = Z;
newF = F;
end
ResBest(dataIndex, tempIndex) = tempResBest(dataIndex, tempIndex);
ResStd(dataIndex, tempIndex) = tempResStd(dataIndex, tempIndex);
end
end
end
end
aRuntime = mean(runtime);
PResBest = ResBest(dataIndex, :);
PResStd = ResStd(dataIndex, :);
save([resultdir2, char(dataname(idata)), char(numname(dataIndex)), 'ACC_', num2str(max(ACC(:))), '_result.mat'], 'ACC', 'NMI', 'Purity', 'aRuntime', ...
'newZ', 'newF', 'PResBest', 'PResStd');
end
save([resultdir2, char(dataname(idata)), '_result.mat'], 'ResBest', 'ResStd');
end