forked from SpanoChristian/IACVProject-MultiDendroCut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasetBenchmark.m
216 lines (193 loc) · 9.23 KB
/
datasetBenchmark.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
addpath(genpath('.'));
% This code just simply run the T-Linkage algorithm on the example data set
% "star5".
% Loading data: X contains data points, whereas G is the ground truth
% segmentation
graphsFolderImgsInlier = "Graphs/Images/InlierVariation/";
graphsFolderFigsInlier = "Graphs/Figures/InlierVariation/";
graphsFolderImgsOutlier = "Graphs/Images/OutlierVariation/";
graphsFolderFigsOutlier = "Graphs/Figures/OutlierVariation/";
epsilonRange = linspace(0.02, 0.25, 10);
outlierRange = linspace(250, 500, 10);
% If the ground truth labels are provided: true
% Otherwise: false
labelled_data = false;
model2fit = 'circle';
for i = 8:8
[X, G, nTotPoints, nRealPoints, nOutliers, nClusters, datasetTitle] = getDatasetAndInfo(labelled_data, i);
if ~labelled_data
G = generateGTLbls(nClusters, 50, nOutliers); %#ok<UNRCH>
end
%[misclassErr, ARI, NMI, ARINMI, lambda1, lambda2, thresholds] = ...
%inlierVariationNew(X, G, epsilonRange, model2fit);
[misclassErrOut, ARIOut, NMIOut, ARINMIOut, lambda1Out, lambda2Out, thresholdsOut] = ...
outlierVariationNew(model2fit, 0.12, outlierRange);
%%
% figure
% subplot(1, 3, 1)
% gscatter(X(1,:), X(2,:), G); axis square; title('GroundTruth');
%
% subplot(1, 3, 2)
% gscatter(X(1,:), X(2,:), C); axis square; title('T-Linkage');
%
% subplot(1, 3, 3)
% gscatter(X(1,:), X(2,:), lblsDynCut); axis square; title('T linkage w/ Dynamic Cut');
%
% saveas(gcf, graphsFolderImgsInlier + datasetTitle + "_ClusterData", 'png');
% saveas(gcf, graphsFolderFigsInlier + datasetTitle + "_ClusterData");
% %% INLIER THRESHOLD ME COMPARISON
% figure
% plot(epsilonRange, misclassErr(:, 1), "-", "LineWidth", 2, ...
% "Marker", "o", "Color", "#0072BD")
% hold on
% plot(epsilonRange, misclassErr(:, 2), "-", "LineWidth", 2, ...
% "Marker", "+", "Color", "#D95319")
% hold on
% plot(epsilonRange, misclassErr(:, 3), "-", "LineWidth", 2, ...
% "Marker", "*", "Color", "#EDB120")
% lgd = legend("T-Linkage ME", "Dynamic T-Linkage ME", "LOF Dynamic T-Linkage ME");
% lgd.FontSize = 15; % Change the font size to 14 points
% title("Comparison T-Linkage vs. [LOF] Dynamic T-Linkage (" + datasetTitle + ")")
% xlabel("\epsilon", "FontSize", 16)
% ylabel("Misclassification Error", "FontSize", 14)
% roof = max([misclassErr(:, 1); misclassErr(:, 2); misclassErr(:, 3)]);
% xlim([min(epsilonRange)-0.005, max(epsilonRange)+0.005])
% ylim([0, roof+0.15])
%
% saveas(gcf, graphsFolderImgsInlier + datasetTitle + "_MEComparison", 'png');
% saveas(gcf, graphsFolderFigsInlier + datasetTitle + "_MEComparison");
%
% %% INLIER THRESHOLD - PARAMETER LAMBDA 1
% figure
% plot(epsilonRange, lambda1, "s-", "LineWidth", 2, "Color", "#0072BD")
% yline(mean(lambda1), "--", mean(lambda1), "LineWidth", 2.3, "Color", "#D95319", ...
% "LabelVerticalAlignment", "Bottom", ...
% "FontSize", 15)
% title("Variation of lambda parameter based on \epsilon")
% xlabel("\epsilon", "FontSize", 16)
% ylabel("\lambda_{1}(\epsilon)", "FontSize", 16)
% legend("\lambda_{1}(\epsilon)", "FontSize", 16)
% xlim([min(epsilonRange)-0.005, max(epsilonRange)+0.005])
% ylim([0, max(lambda1)+15])
%
% saveas(gcf, graphsFolderImgsInlier + datasetTitle + "_Lambda1Variation", 'png');
% saveas(gcf, graphsFolderFigsInlier + datasetTitle + "_Lambda1Variation");
%
% %% INLIER THRESHOLD - PARAMETER LAMBDA 2
% figure
% plot(epsilonRange, lambda2, "s-", "LineWidth", 2, "Color", "#0072BD")
% yline(mean(lambda2), "--", mean(lambda2), "LineWidth", 2.3, "Color", "#D95319", ...
% "LabelVerticalAlignment", "Bottom", ...
% "FontSize", 15)
% title("Variation of lambda parameter based on \epsilon")
% xlabel("\epsilon", "FontSize", 16)
% ylabel("\lambda_{2}(\epsilon)", "FontSize", 16)
% legend("\lambda_{2}(\epsilon)", "FontSize", 16)
% xlim([min(epsilonRange)-0.005, max(epsilonRange)+0.005])
% ylim([0, max(lambda2)+15])
%
% saveas(gcf, graphsFolderImgsInlier + datasetTitle + "_Lambda2Variation", 'png');
% saveas(gcf, graphsFolderFigsInlier + datasetTitle + "_Lambda2Variation");
%
% %% Improvement Comparison - How much our algorithm impact on ME?
%
% % LOF Dynamic T-Linkage vs T-Linkage
% LOFDynVsTlnk = misclassErr(:, 1) - misclassErr(:, 3);
%
% % Dynamic T-Linkage vs T-Linkage
% DynVsTlnk = misclassErr(:, 1) - misclassErr(:, 2);
%
% figure
% bar(epsilonRange, [LOFDynVsTlnk'; DynVsTlnk'])
% legend("LOF", "DYN", "Location", "Best", "FontSize", 14)
% title("Improvement of [LOF] Dynamic T-Linkage", "FontSize", 15)
% xlabel("\epsilon", "FontSize", 16)
% ylabel("% ME Improved", "FontSize", 15)
%
% saveas(gcf, graphsFolderImgsInlier + datasetTitle + "_ImprovementPerc", 'png');
% saveas(gcf, graphsFolderFigsInlier + datasetTitle + "_ImprovementPerc");
% INLIER THRESHOLD COMPARISON - ARI & NMI
% figure
% %load("./DendrogramUtils/Scores&Params_InlierThresholdComparison.mat")
% v = 0.005:0.0075:0.2;
% plot(v, ARI(:, 1), "o--", "LineWidth", 2, "Color", "#D95319")
% hold on
% plot(v, ARI(:, 2), "s-", "LineWidth", 2, "Color", "#0072BD")
% % plot(v, smoothdata(nmiScore(:, 1)), "--", "LineWidth", 2, "Color", "#0072BD")
% % plot(v, smoothdata(nmiScore(:, 2)), "-", "LineWidth", 2, "Color", "#0072BD")
% lgd = legend("T-Linkage ARI \times NMI", "LOF Dynamic T-Linkage ARI \times NMI");
% lgd.FontSize = 15; % Change the font size to 14 points
% title("Comparison T-Linkage vs. LOF Dynamic T-Linkage")
% xlabel("\epsilon", "FontSize", 16)
% ylabel("ARI \times NMI", "FontSize", 14)
%% ---------------------------------------------------
%%
outlierRange = ((outlierRange-250)/250);
%% OUTLIER THRESHOLD ME COMPARISON
figure
plot(outlierRange, misclassErrOut(:, 1), "-", "LineWidth", 2, ...
"Marker", "o", "Color", "#0072BD")
hold on
plot(outlierRange, misclassErrOut(:, 2), "-", "LineWidth", 2, ...
"Marker", "+", "Color", "#D95319")
hold on
plot(outlierRange, misclassErrOut(:, 3), "-", "LineWidth", 2, ...
"Marker", "*", "Color", "#EDB120")
lgd = legend("T-Linkage ME", "Dynamic T-Linkage ME", "LOF Dynamic T-Linkage ME");
lgd.FontSize = 15; % Change the font size to 14 points
title("Comparison T-Linkage vs. [LOF] Dynamic T-Linkage (" + datasetTitle + ")")
xlabel("Outlier %", "FontSize", 16)
ylabel("Misclassification Error", "FontSize", 14)
roof = max([misclassErrOut(:, 1); misclassErrOut(:, 2); misclassErrOut(:, 3)]);
xlim([min(outlierRange)-0.005, max(outlierRange)+0.005])
ylim([0, roof+0.15])
saveas(gcf, graphsFolderImgsOutlier + datasetTitle + "_MEComparison", 'png');
saveas(gcf, graphsFolderFigsOutlier + datasetTitle + "_MEComparison");
%% OUTLIER THRESHOLD - PARAMETER LAMBDA 1
figure
plot(outlierRange, lambda1Out, "s-", "LineWidth", 2, "Color", "#0072BD")
yline(mean(lambda1Out), "--", mean(lambda1Out), "LineWidth", 2.3, "Color", "#D95319", ...
"LabelVerticalAlignment", "Bottom", ...
"FontSize", 15)
title("Variation of \lambda_{1} parameter based on outlier %")
xlabel("Outlier %", "FontSize", 16)
ylabel("\lambda_{1}(out%)", "FontSize", 16)
legend("\lambda_{1}(out%)", "FontSize", 16)
xlim([min(outlierRange)-0.005, max(outlierRange)+0.005])
ylim([0, max(lambda1Out)+15])
saveas(gcf, graphsFolderImgsOutlier + datasetTitle + "_Lambda1Variation", 'png');
saveas(gcf, graphsFolderFigsOutlier + datasetTitle + "_Lambda1Variation");
%% OUTLIER THRESHOLD - PARAMETER LAMBDA 2
figure
plot(outlierRange, lambda2Out, "s-", "LineWidth", 2, "Color", "#0072BD")
yline(mean(lambda2Out), "--", mean(lambda2Out), "LineWidth", 2.3, "Color", "#D95319", ...
"LabelVerticalAlignment", "Bottom", ...
"FontSize", 15)
title("Variation of \lambda_{2} parameter based on outlier %")
xlabel("Outlier %", "FontSize", 16)
ylabel("\lambda_{2}(out%)", "FontSize", 16)
legend("\lambda_{2}(out%)", "FontSize", 16)
saveas(gcf, graphsFolderImgsOutlier + datasetTitle + "_Lambda2Variation", 'png');
saveas(gcf, graphsFolderFigsOutlier + datasetTitle + "_Lambda2Variation");
%% Improvement Comparison - How much our algorithm impact on ME?
% LOF Dynamic T-Linkage vs T-Linkage
LOFDynVsTlnk = misclassErrOut(:, 3) - misclassErrOut(:, 1);
% Dynamic T-Linkage vs T-Linkage
DynVsTlnk = misclassErrOut(:, 2) - misclassErrOut(:, 1);
figure
bar(outlierRange, [LOFDynVsTlnk'; DynVsTlnk'])
legend("LOF", "DYN", "Location", "Best", "FontSize", 14)
title("Delta ME [LOF] Dyn T-Link vs T-Link", "FontSize", 15)
xlabel("Outlier %", "FontSize", 16)
ylabel("Delta % ME", "FontSize", 15)
%xlim([min(epsilonRange)-0.05, max(epsilonRange)+0.005])
ylim( [ ...
min( ...
[LOFDynVsTlnk'; DynVsTlnk'] ...
)-0.05, ...
max( ...
[LOFDynVsTlnk'; DynVsTlnk'] ...
)+0.05 ])
saveas(gcf, graphsFolderImgsOutlier + datasetTitle + "_ImprovementPerc", 'png');
saveas(gcf, graphsFolderFigsOutlier + datasetTitle + "_ImprovementPerc");
end