-
Notifications
You must be signed in to change notification settings - Fork 0
/
evaluation.m
58 lines (52 loc) · 1.97 KB
/
evaluation.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
function [score, recall, retrieved_total] = evaluation(Wtrue, Dhat)
%
% Input:
% Wtrue = true neighbors [Ntest * Ndataset], can be a full matrix NxN
% Dhat = estimated distances
% The next inputs are optional:
% fig = figure handle
% options = just like in the plot command
%
% Output:
%
% exp. # of good pairs inside hamming ball of radius <= (n-1)
% score(n) = --------------------------------------------------------------
% exp. # of total pairs inside hamming ball of radius <= (n-1)
%
% exp. # of good pairs inside hamming ball of radius <= (n-1)
% recall(n) = --------------------------------------------------------------
% exp. # of total good pairs
[Ntest, Ntrain] = size(Wtrue);
total_good_pairs = sum(Wtrue(:))
query_num = 2000;
display('good_pairs_per_query:');
display(total_good_pairs/query_num);
% find pairs with similar codes
num = 15;
score = zeros(num,1);
recall = zeros(num,1);
retrieved_good = zeros(num,1);
retrieved_total = zeros(num,1);
for n = 1:length(score)
j = find(Dhat<=((n-1)+0.00001));
%exp. # of good pairs that have exactly the same code per query
retrieved_good_pairs = sum(Wtrue(j));
retrieved_good(n) = retrieved_good_pairs/query_num;
% exp. # of total pairs that have exactly the same code per query
retrieved_pairs = length(j);
retrieved_total(n) = retrieved_pairs/query_num;
score(n) = retrieved_good_pairs/retrieved_pairs;
recall(n)= retrieved_good_pairs/total_good_pairs;
end
display('retrieved good pairs:');
display(retrieved_good);
% The standard measures for IR are recall and precision. Assuming that:
%
% * RET is the set of all items the system has retrieved for a specific inquiry;
% * REL is the set of relevant items for a specific inquiry;
% * RETREL is the set of the retrieved relevant items
%
% then precision and recall measures are obtained as follows:
%
% precision = RETREL / RET
% recall = RETREL / REL