bc... [hack]
Home » Source Code » Hash algorithms » lshcode/lshlookup.m

lshcode/lshlookup.m ( File view )

  • By 毛宁 2014-10-28
  • View(s):33
  • Download(s):0
  • Point(s): 1
			function [iNN,cand] = lshlookup(x0,x,T,varargin)
% [iNN,cand] = lshlookup(x0,x,T)
%
%   iNN contains indices of matches in T for a single query x0;
%   x is the representation in the feature space; assumes to be a cell
%   array with equal size cells (this is a hack around Matlab's problem
%   with allocating large contiguous chunks of memory);
%   dfun is the dist. function ('l1','l2','cos')
%   
%   returns in iNN the indices of the found NN; cand is the # of 
%   examined candidates (i.e., size of the union of the matching buckets
%   in all tables)
%
% Optional arguments:
%
%   'k' : if given, return this many neighbors (default 1)
%   'sel' : if 'random', select random neighbors matching other
%     criteria. If 'best', select best (closest) matches. Default is 'best'.
%   'r' : max. distance cut-off
%   'distfun', 'distargs' : distance function (and additional args.) to
%     use. Default: L1 if T.type is 'lsh' and L2 if it's 'e2lsh'.
%   'verb' : verbosity (overrides T.verbose)
%
% (C) Greg Shakhnarovich, TTI-Chicago (2008)

distfun='lpnorm';
switch T(1).type,
 case 'lsh', distargs={
1
};
 case 'e2lsh', distargs={
2
};
end
k=1;
r=inf;
sel='best';
f=[];
fargs=[];
verb=T(1).verbose;

% parse args.
for a=1:2:length(varargin)
  eval(sprintf('%s = varargin{
a+1
};',varargin{
a
}));
end


l = length(T);

iNN=[];

% find the union of buckets in all tables that match query
for j=1:l
  % look up T_j
  % buck is the # of bucket in T{
j
}
  buck = findbucket(T(j).type,x0,T(j).I);
  % find the bucket in j-th table
  key = lshhash(buck);
  ihash = T(j).bhash{
key
}; % possible matching buckets
  if (~isempty(ihash)) % nothing matches
    b = ihash(find(all(bsxfun(@eq,buck,T(j).buckets(ihash,:)),2)));
    if (~isempty(b))
      iNN = [iNN T(j).Index{
b
}];
    end
  end
end

% delete duplicates
[iNN,iu]=unique(iNN);
cand = length(iNN);

% now iNN has the collection of candidate indices 
% we can start examining them

if (verb > 0)
  fprintf('Examining %d candidates\n',cand);
end

if (~isempty(iNN))
  
  if (strcmp(sel,'best'))

    D=feval(distfun,x0,Xsel(x,iNN),distargs{
:
});
    [d
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
0.00 B2009-06-26|22:00
findbucket.m653.00 B2008-11-10|12:45
lpnorm.m3.79 kB2008-11-10|12:45
lsh.m3.18 kB2008-11-10|12:45
lshfunc.m2.94 kB2008-11-10|12:45
lshhash.m957.00 B2008-11-10|12:45
lshins.m3.21 kB2008-11-10|12:45
lshlookup.m3.07 kB2009-06-26|21:35
lshprep.m1.56 kB2008-11-10|12:45
lshstats.m2.36 kB2009-06-26|21:36
processRange.m1.01 kB2008-11-10|12:45
README10.58 kB2009-06-26|22:00
...

lshcode/lshlookup.m (12.66 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D