|
a |
|
b/functions/functions_Classifiers/computeCMC.m |
|
|
1 |
function [cmcPad, cmc_sum] = computeCMC(distMatrix, TestLabels, titleS, plotta) |
|
|
2 |
|
|
|
3 |
truncCMC = 100; |
|
|
4 |
|
|
|
5 |
clear rankV |
|
|
6 |
rankV = zeros(size(distMatrix, 1), 1); |
|
|
7 |
for r = 1 : size(distMatrix, 1) |
|
|
8 |
|
|
|
9 |
distV = distMatrix(r, :); |
|
|
10 |
sortV = sort(distV, 'ascend'); |
|
|
11 |
sortV(1) = []; |
|
|
12 |
|
|
|
13 |
minD = sortV(1); %the first will be 0 |
|
|
14 |
idx = find(distV == minD); |
|
|
15 |
idx = idx(1); %se dovessero essercene altri a pari merito |
|
|
16 |
|
|
|
17 |
rankV(r) = 1; |
|
|
18 |
|
|
|
19 |
while (TestLabels(idx) ~= TestLabels(r)) && (length(sortV) >= 2) |
|
|
20 |
|
|
|
21 |
sortV(1) = []; |
|
|
22 |
minD = sortV(1); |
|
|
23 |
idx = find(distV == minD); |
|
|
24 |
idx = idx(1); %se dovessero essercene altri a pari merito |
|
|
25 |
|
|
|
26 |
rankV(r) = rankV(r) + 1; |
|
|
27 |
|
|
|
28 |
end %while strcmp |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
end %for r |
|
|
32 |
|
|
|
33 |
% |
|
|
34 |
probRanks = countmember(1:max(rankV), rankV) ./ size(distMatrix, 1); |
|
|
35 |
clear cmc |
|
|
36 |
cmc = zeros(length(probRanks), 1); |
|
|
37 |
for i = 1 : length(probRanks) |
|
|
38 |
if i == 1 |
|
|
39 |
cmc(i) = probRanks(i); |
|
|
40 |
else |
|
|
41 |
cmc(i) = cmc(i-1) + probRanks(i); |
|
|
42 |
end %if i |
|
|
43 |
end %for i |
|
|
44 |
|
|
|
45 |
%truncate cmc |
|
|
46 |
%cmc = cmc(1 : truncCMC); |
|
|
47 |
|
|
|
48 |
padExtra = 30; |
|
|
49 |
if numel(cmc) < padExtra |
|
|
50 |
cmcPad = padarray(cmc, padExtra-numel(cmc), 1, 'post'); |
|
|
51 |
else |
|
|
52 |
cmcPad = cmc; |
|
|
53 |
end |
|
|
54 |
|
|
|
55 |
%cmc_sum |
|
|
56 |
cmc_sum = sum(cmcPad(:)); |
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
%plot |
|
|
61 |
if plotta |
|
|
62 |
fsfigure; |
|
|
63 |
fs = 24; |
|
|
64 |
plot(cmcPad, 'r-h', 'linewidth', 2, 'Markersize', 15); |
|
|
65 |
xlabel('Rank', 'fontsize', fs) |
|
|
66 |
ylabel('Identification Rate (%)', 'fontsize',fs) |
|
|
67 |
grid on |
|
|
68 |
title(titleS, 'fontsize', fs) |
|
|
69 |
hold on |
|
|
70 |
set(gca, 'fontsize', fs) |
|
|
71 |
set(gcf, 'color', 'w'); |
|
|
72 |
axis([0 padExtra 0.80 1]); |
|
|
73 |
end %if plot |
|
|
74 |
|
|
|
75 |
|