在用哈希进行检索时,常会用到precision recall曲线对其性能进行定量评价。precision recall的定义在信息检索评价指标中已做了详细说明,这里再记录一下precision recall的具体实现。
precision recall曲线matlab一般使用的都是下面的版本:
function [recall, precision, rate] = recall_precision(Wtrue, Dhat)
%
% Input:
% Wtrue = true neighbors [Ntest * Ndataset], can be a full matrix NxN
% Dhat = estimated distances
%
% Output:
%
% exp. # of good pairs inside hamming ball of radius <= (n-1)
% precision(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
max_hamm = max(Dhat(:))
hamm_thresh = min(3,max_hamm);
[Ntest, Ntrain] = size(Wtrue);
total_good_pairs = sum(Wtrue(:));
% find pairs with similar codes
precision = zeros(max_hamm,1);
recall = zeros(max_hamm,1);
rate = zeros(max_hamm,1);
for n = 1:length(precision)
j = (Dhat<=((n-1)+0.00001));
%exp. # of good