-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmoothingOnCorrelationsTest.m
112 lines (74 loc) · 2.78 KB
/
smoothingOnCorrelationsTest.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
%% SmoothingOnCorrelationsTest
for ix = 1:length(d_q) % for all the positions in a corridor
[distances_all{ix}] = getDistancesBetweenDescriptors(d_q{ix},d_db,0,3);
end
%% Scaling (converting from Euclidean distances to 'correlation' or RHO
Max = max(cell2mat(cellfun(@(x) max(x(:)),distances_all,'UniformOutput',0)));
numConsecSamples = 100; % Number of consecutive samples to take
% into account for the quantification of the
% similarity. 100 samples ~ 2m
for ix = 1:length(d_q)
correlations_all{ix} = (-distances_all{ix}+Max)/Max;
% This smooth provides the equivalent of taking consecutive samples
% from the database
smoothed_correlations{ix} = smooth(correlations_all{ix},numConsecSamples);
end
%%
surrounding = 50; %
for ix = 1:length(d_q) % for all the positions in a corridor
central_point = gt_q(ix); % Get ground truth position of the QUERY
%% Surrounding locations
% Get the closest SURROUNDING positions from the DATABASE
[idx_surr_min,~,idx_surr_max] = ...
getDBindicesOfSurroundingQueriesInCentimetres(central_point,surrounding,gt_db);
% Get the descriptor corresponding to DATABASE images at those locations
idx_surrounding = idx_surr_min:idx_surr_max;
values_within{ix} = smoothed_correlations{ix}(idx_surrounding);
%% 'Far' locations
% Get the descriptor corresponding to DATABASE images at those FAR locations
idx_all = 1:length(d_db);
idx_beyond = setdiff(idx_all,idx_surrounding);
values_beyond{ix} = smoothed_correlations{ix}(idx_beyond);
end
%% WITHIN-BEYOND distributions (PDF)
x = linspace(0,1,100);
[n_within,~] = hist(cat(1,values_within{:}),x);
pdf_within = n_within/sum(n_within);
[n_beyond] = hist(cat(1,values_beyond{:}),x);
pdf_beyond = n_beyond/sum(n_beyond);
% PLOTS:
figure
plot(x,smooth(smooth(pdf_within)));
hold on
plot(x,smooth(smooth(pdf_beyond)),'r');
%% ROC curves
cs_within = cumsum(pdf_within); % Because our pdfs are discrete, the discrete cumsum can be used.
cs_beyond = cumsum(pdf_beyond);
% ROC plots (one at a time)
figure;
plot(cs_within,cs_beyond)
hold on
axis tight
%% ROC plots (alltogether)
% Comment out the corresponding instructions, one at a time.
% cs_within_1= cs_within;
% cs_beyond_1 = cs_beyond;
% cs_within_3= cs_within;
% cs_beyond_3 = cs_beyond;
% cs_within_5= cs_within;
% cs_beyond_5 = cs_beyond;
% cs_within_11= cs_within;
% cs_beyond_11 = cs_beyond;
cs_within_20= cs_within;
cs_beyond_20 = cs_beyond;
%%
figure;
plot(cs_within_1,cs_beyond_1)
hold on
axis tight
plot(cs_within_3,cs_beyond_3,'r')
plot(cs_within_5,cs_beyond_5,'g')
plot(cs_within_11,cs_beyond_11,'k')
% plot(cs_within_20,cs_beyond_20,'m')
legend('K=1','K=3','K=5','K=11')
% legend('K=1','K=3','K=5','K=11', 'K=20')