Switch to unified view

a b/functions/functions_Classifiers/computeCMC_trainTest.m
1
function [cmcPad, cmc_sum] = computeCMC_trainTest(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
cmcPad = padarray(cmc, padExtra-numel(cmc), 1, 'post');
50
51
%cmc_sum
52
cmc_sum = sum(cmcPad(:));
53
54
55
56
%plot
57
if plotta
58
    fsfigure;
59
    fs = 24;
60
    plot(cmcPad, 'r-h', 'linewidth', 2, 'Markersize', 15);
61
    xlabel('Rank', 'fontsize', fs)
62
    ylabel('Identification Rate (%)', 'fontsize',fs)
63
    grid on
64
    title(titleS, 'fontsize', fs)
65
    hold on
66
    set(gca, 'fontsize', fs)
67
    set(gcf, 'color', 'w');
68
    axis([0 padExtra 0.80 1]);
69
end %if plot
70
71