-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontinuousWithinBeyondFunction.m
127 lines (77 loc) · 2.99 KB
/
continuousWithinBeyondFunction.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
%% continuousWithinBeyondFunction Test
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)));
% Eliminate NaNs
% for jj = 1:length(distances_all)
% distances_all{jj}(isnan(distances_all{jj})) = Max;
% end
numConsecSamples = 1; % 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
%% The test
x = linspace(0,1,100);
N = 10; % Level of randomization
wb = waitbar(0,'Please wait, obtaining correlations value...');
for ix = 1:1:N % for N random experiments
rnd_idx = randi(length(gt_q),1);
central_point = gt_q(rnd_idx); % Get ground truth position of the QUERY
S = 3000; % S is the span of surrounding locations from which to calculate the values
%for s = 1:1:gt_q(end)-50
for s = 1:1:S
surrounding = (s-1)+50; %
%% Surrounding locations
% Get the closest SURROUNDING positions from the DATABASE
[idx_surr_min,~,idx_surr_max] = ...
getDBindicesOfSurroundingQueriesInCentimetres(central_point,surrounding,gt_db);
% Get the smoothed correlation values corresponding to DATABASE images at those locations
idx_surrounding = idx_surr_min:idx_surr_max;
values_within{ix}{s} = smoothed_correlations{rnd_idx}(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}{s} = smoothed_correlations{rnd_idx}(idx_beyond);
%% Within-beyond distributions (PDFs)
[n_within,~] = hist(values_within{ix}{s},x);
pdf_within{ix}{s} = n_within/sum(n_within);
[n_beyond] = hist(values_beyond{ix}{s},x);
pdf_beyond{ix}{s} = n_beyond/sum(n_beyond);
a = double(s);
b = double(S);
waitbar(a/b);
end
end
close(wb)
%%
% PLOTS:
%
% figure
% plot(x,smooth(smooth(pdf_within)));
% hold on
% plot(x,smooth(smooth(pdf_beyond)),'r');
%% Plots
N_hist = length(pdf_within);
within = zeros(N_hist,S,100);
beyond = zeros(size(within));
for ix = 1:N_hist
within(ix,:,:) = cell2mat(cat(1,pdf_within{ix}(:)));
beyond(ix,:,:) = cell2mat(cat(1,pdf_beyond{ix}(:)));
end
%%
x = linspace(0,1,100);
y = 0:0.01:30-0.01;
figure
Z_within = squeeze(mean(within,1));
mesh(x,y,Z_within);
figure
Z_beyond = squeeze(mean(beyond,1));
mesh(x,y,Z_beyond);