-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEMRtest.m
69 lines (52 loc) · 1.35 KB
/
EMRtest.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
function [score] = EMRtest(x,model)
% [score] = EMRtest(x,model): Efficient Manifold Ranking for out-of-sample
% retrieval
% Input:
% - x: the query point, row vector.
% - model: the model learned by EMR
%
% Output:
% - score: the ranking scores for each point in the database
%
% Usage:
%
% See: http://www.zjucadcg.cn/dengcai/Data/Examples.html#EMR
%
%Reference:
%
% Bin Xu, Jiajun Bu, Chun Chen, Deng Cai, Xiaofei He, Wei Liu, Jiebo
% Luo, "Efficient Manifold Ranking for Image Retrieval",in Proceeding of
% the 34th International ACM SIGIR Conference on Research and
% Development in Information Retrieval (SIGIR), 2011, pp. 525-534.
%
% version 2.0 --Feb./2012
% version 1.0 --Sep./2010
%
% Written by Bin Xu (binxu986 AT gmail.com)
% Deng Cai (dengcai AT gmail.com)
r = model.r;
a = model.a;
p = size(model.landmarks,1);
% Z construction
D = EuDist2(x,model.landmarks);
[dump,idx] = sort(D);
dump = dump(1:r)/dump(r);
dump = 0.75 * (1 - dump.^2);
z = sparse(idx(1:r),1,dump,p,1);
Z = [model.Z z];
Z = Z';
nSmp =size(Z,1);
y0 = zeros(nSmp,1);
y0(end) = 1;
% Efficient Ranking
feaSum = full(sum(Z,1));
D = Z*feaSum';
D = max(D, 1e-12);
D = D.^(-.5);
H = spdiags(D,0,nSmp,nSmp)*Z;
C = speye(p);
A = H'*H-(1/a)*C;
tmp = H'*y0;
tmp = A\tmp;
score = y0 - H*tmp;
score(end) = [];