-
Notifications
You must be signed in to change notification settings - Fork 10
/
main_demo.m
170 lines (156 loc) · 4.78 KB
/
main_demo.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
close all; clear all; clc;
addpath('./utils/');
db_name = 'MNIST&USPS';
param.choice = 'evaluation_PR_MAP';
loopnbits = [32 64];
num_test=500;
runtimes = 1; % change several times to make the rusult more smooth
param.pos = [1:10:40 50:50:1000]; % The number of retrieved samples: Recall-The number of retrieved samples curve
hashmethods = {'PWCF'};
nhmethods = length(hashmethods);
for k = 1:runtimes
fprintf('The %d run time, start constructing data\n\n', k);
exp_data = construct_dataset(db_name,num_test,0);
fprintf('Constructing data finished\n\n');
for i =1:length(loopnbits)
fprintf('======start %d bits encoding======\n\n', loopnbits(i));
param.r = loopnbits(i);
for j = 1:nhmethods
[recall{k}{i, j}, precision{k}{i, j}, mAP{k}{i,j}, rec{k}{i, j}, pre{k}{i, j}, ~] = demo(exp_data, param, hashmethods{1, j});
end
end
end
% plot attribution
line_width = 1.5;
marker_size = 4;
xy_font_size = 16;
legend_font_size = 14;
linewidth = 1.6;
title_font_size = 18;
% average MAP
for j = 1:nhmethods
for i =1: length(loopnbits)
tmp = zeros(size(mAP{1, 1}{i, j}));
for k = 1:runtimes
tmp = tmp+mAP{1, k}{i, j};
end
MAP{i, j} = tmp/runtimes;
end
clear tmp;
end
MAP
choose_bits = 1; % i: choose the bits to show
choose_times = 1; % k is the times of run times
%% show recall vs. the number of retrieved sample.
figure('Color', [1 1 1]); hold on;
posEnd = 8;
for j = 1: nhmethods
pos = param.pos;
recc = rec{choose_times}{choose_bits, j};
%p = plot(pos(1,1:posEnd), recc(1,1:posEnd));
p = plot(pos(1,1:end), recc(1,1:end));
color = gen_color(j);
marker = gen_marker(j);
set(p,'Color', color)
set(p,'Marker', marker);
set(p,'LineWidth', line_width);
set(p,'MarkerSize', marker_size);
end
str_nbits = num2str(loopnbits(choose_bits));
set(gca, 'linewidth', linewidth);
h1 = xlabel('The number of retrieved samples');
h2 = ylabel(['Recall @ ', str_nbits, ' bits']);
title(db_name, 'FontSize', title_font_size);
set(h1, 'FontSize', xy_font_size);
set(h2, 'FontSize', xy_font_size);
%axis square;
hleg = legend(hashmethods);
set(hleg, 'FontSize', legend_font_size);
set(hleg,'Location', 'best');
box on;
grid on;
hold off;
%% show precision vs. the number of retrieved sample.
figure('Color', [1 1 1]); hold on;
posEnd = 8;
for j = 1: nhmethods
pos = param.pos;
prec = pre{choose_times}{choose_bits, j};
%p = plot(pos(1,1:posEnd), recc(1,1:posEnd));
p = plot(pos(1,1:end), prec(1,1:end));
color = gen_color(j);
marker = gen_marker(j);
set(p,'Color', color)
set(p,'Marker', marker);
set(p,'LineWidth', line_width);
set(p,'MarkerSize', marker_size);
end
str_nbits = num2str(loopnbits(choose_bits));
set(gca, 'linewidth', linewidth);
h1 = xlabel('The number of retrieved samples');
h2 = ylabel(['Precision @ ', str_nbits, ' bits']);
title(db_name, 'FontSize', title_font_size);
set(h1, 'FontSize', xy_font_size);
set(h2, 'FontSize', xy_font_size);
%axis square;
hleg = legend(hashmethods);
set(hleg, 'FontSize', legend_font_size);
set(hleg,'Location', 'best');
box on;
grid on;
hold off;
%% show precision vs. recall , i is the selection of which bits.
figure('Color', [1 1 1]); hold on;
for j = 1: nhmethods
p = plot(recall{choose_times}{choose_bits, j}, precision{choose_times}{choose_bits, j});
color=gen_color(j);
marker=gen_marker(j);
set(p,'Color', color)
set(p,'Marker', marker);
set(p,'LineWidth', line_width);
set(p,'MarkerSize', marker_size);
end
str_nbits = num2str(loopnbits(choose_bits));
h1 = xlabel(['Recall @ ', str_nbits, ' bits']);
h2 = ylabel('Precision');
title(db_name, 'FontSize', title_font_size);
set(h1, 'FontSize', xy_font_size);
set(h2, 'FontSize', xy_font_size);
%axis square;
hleg = legend(hashmethods);
set(hleg, 'FontSize', legend_font_size);
set(hleg,'Location', 'best');
set(gca, 'linewidth', linewidth);
box on;
grid on;
hold off;
%% show mAP. This mAP function is provided by Yunchao Gong
figure('Color', [1 1 1]); hold on;
for j = 1: nhmethods
map = [];
for i = 1: length(loopnbits)
map = [map, MAP{i, j}];
end
p = plot(log2(loopnbits), map);
color=gen_color(j);
marker=gen_marker(j);
set(p,'Color', color);
set(p,'Marker', marker);
set(p,'LineWidth', line_width);
set(p,'MarkerSize', marker_size);
end
h1 = xlabel('Number of bits');
h2 = ylabel('mean Average Precision (mAP)');
title(db_name, 'FontSize', title_font_size);
set(h1, 'FontSize', xy_font_size);
set(h2, 'FontSize', xy_font_size);
%axis square;
set(gca, 'xtick', log2(loopnbits));
set(gca, 'XtickLabel', {'16','32','48' '64','96','128'});
set(gca, 'linewidth', linewidth);
hleg = legend(hashmethods);
set(hleg, 'FontSize', legend_font_size);
set(hleg, 'Location', 'best');
box on;
grid on;
hold off;