-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo2.m
95 lines (84 loc) · 3.3 KB
/
demo2.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
%% Generate test datasets
close all;
addpath(genpath(pwd));
disp('first generate a set of datasets (by sampling different number of samples from 5 different sampling functions)...')
data_names ={'TB', 'SF', 'CC', 'CG', 'Flower'};
for name_id=1:length(data_names)
exponents = 14:20;
for exponent_id = 1:length(exponents)
dataSize = 2.^exponents(exponent_id);
dataName = data_names{name_id};
disp(['generate dataset: ',dataName,'_',num2str(dataSize),':'])
fileName = ['data_',data_names{name_id},'_',num2str(dataSize),'.mat'];
if ~exist(fileName,'file')
figure;
synthesizeLargescaleDatasets_withArbitrarySizes(dataName,dataSize);
close(gcf)
end
end
end
disp('Start testing ...')
%% start testing
method_names = {'FastLDPMST'};
%% start testing
plot_flag = 1;
Result_all = [];test_num = 1;
for method_id = 1:length(method_names)
method = method_names{method_id};
for name_id=1:length(data_names)
exponents = 14:20;
for exponent_id = 1:length(exponents)
%% load dataset
clear data annotation_data
dataSize = 2.^exponents(exponent_id);
dataName = data_names{name_id};
disp(['data ', num2str(test_num),': ',dataName,'_',num2str(dataSize),':'])
fileName = ['data_',data_names{name_id},'_',num2str(dataSize),'.mat'];
if ~exist(fileName,'file')
figure;
synthesizeLargescaleDatasets_withArbitrarySizes(dataName,dataSize);
close(gcf)
end
load(fileName);
annotation_data = gt;
data = fea;
clear fea; clear gt;
if (min(annotation_data) == 0)
annotation_data = annotation_data+1;
end
data = double(data);
[N,dim]=size(data);
nC = length(unique(annotation_data)); % number of clusters
disp(['#objects: ',num2str(N),'; #features: ',num2str(dim)])
%% parameter setting
ratio = 0.018; % [0.01,0.02] is recommended; not needed for manual cutting;
MinSize= ratio*N;
%% compared methods
switch method
case 'FastLDPMST'
[Label,time] = FastLDPMST(data, nC, MinSize); %%
otherwise
error('method is not included...please name the method appropriately.')
end
%% Evaluate results
clear data
Result_all(test_num).data_name = [dataName,'_',num2str(dataSize)];
Result_all(test_num).N = N;
if exist('annotation_data','var')
disp('evaluate the clustering result...')
[NMI,ARI]= NMI_ARI(Label,annotation_data);
Result_all(test_num).NMI = roundn(NMI,-3);
Result_all(test_num).ARI = roundn(ARI,-3);
end
Result_all(test_num).time = roundn(time,-3);
Result_all(test_num).method = method;
test_num = test_num + 1;
disp(" "); disp(" ");
if time > 1800 % half an hour
break;
end
end
end
%% save result
disp(struct2table(Result_all, 'AsArray', true))
end