PQ
Load data and set parameter
第一步是载入数据和设定参数。
载入数据,random生成数据可以不需要数据集。
以下是载入数据的代码:
% Generate or load an evaluation set (query+learn+base)
if strcmp (dataset, 'random')
% synthetic dataset
d = 16;
% Generate a set of unit norm vectors
ntrain = 10000;
nbase = 1000000;
nquery = 1000;
% 随机生成d * n维的矩阵
vtrain = single (rand (d, ntrain));
vbase = single (rand (d, nbase));
vquery = single (rand (d, nquery));
% Compute the ground-truth
t0 = cputime;
[ids_gnd, dis_gnd] = yael_nn (vbase, vquery, 1);
tgnd = cputime - t0;
else
switch dataset
case 'siftsmall'
basedir = './siftsmall/' ; % modify this directory to fit your configuration
fbase = [basedir 'siftsmall_base.fvecs'];
fquery = [basedir 'siftsmall_query.fvecs'];
ftrain = [basedir 'siftsmall_learn.fvecs'];
fgroundtruth = [basedir 'siftsmall_groundtruth.ivecs'];
case 'sift'
basedir = './sift/' ; % modify this directory to fit your configuration
fbase = [basedir 'sift_base.fvecs'];
fquery = [basedir 'sift_query.fvecs'];
ftrain = [basedir 'sift_learn.fvecs'];
fgroundtruth = [basedir 'sift_groundtruth.ivecs'];
case 'gist'
basedir = './gist/' ; % modify this directory to fit your configuration
fbase = [basedir 'gist_base.fvecs'];
fquery = [basedir 'gist_query.fvecs'];
ftrain = [basedir 'gist_learn.fvecs'];
fgroundtruth = [basedir 'gist_groundtruth.ivecs'];
end
% Read the vectors
vtrain = fvecs_read (ftrain);
vbase = fvecs_read (fbase);
vquery = fvecs_read (fquery);
ntrain = size (vtrain, 2);
nbase = size (vbase, 2);
nquery = size (vquery, 2);
d = size (vtrain, 1);
% Load the groundtruth
ids = ivecs_read (fgroundtruth);
ids_gnd = ids (1, :) + 1; % matlab indices start at 1
end
在随机生成数据的代码中,调用yael_nn函数来生成ground-truth。
之后设定搜索过程中的参数:
k = 100; % number of elements to be returned