Mercurial > hg > camir-aes2014
comparison toolboxes/distance_learning/mlr/separationOracle/separationOracleAUC.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [Y, Loss] = separationOracleAUC(q, D, pos, neg, k) | |
2 % | |
3 % [Y,Loss] = separationOracleAUC(q, D, pos, neg, k) | |
4 % | |
5 % q = index of the query point | |
6 % D = the current distance matrix | |
7 % pos = indices of relevant results for q | |
8 % neg = indices of irrelevant results for q | |
9 % k = length of the list to consider (unused in AUC) | |
10 % | |
11 % Y is a permutation 1:n corresponding to the maximally | |
12 % violated constraint | |
13 % | |
14 % Loss is the loss for Y, in this case, 1-AUC(Y) | |
15 | |
16 | |
17 % First, sort the documents in descending order of W'Phi(q,x) | |
18 % Phi = - (X(q) - X(x)) * (X(q) - X(x))' | |
19 | |
20 % Sort the positive documents | |
21 ScorePos = - D(pos,q); | |
22 [Vpos, Ipos] = sort(full(ScorePos'), 'descend'); | |
23 Ipos = pos(Ipos); | |
24 | |
25 % Sort the negative documents | |
26 ScoreNeg = - D(neg,q); | |
27 [Vneg, Ineg] = sort(full(ScoreNeg'), 'descend'); | |
28 Ineg = neg(Ineg); | |
29 | |
30 | |
31 % How many pos and neg documents are we using here? | |
32 numPos = length(pos); | |
33 numNeg = length(neg); | |
34 n = numPos + numNeg; | |
35 | |
36 | |
37 NegsBefore = sum(bsxfun(@lt, Vpos, Vneg' + 0.5),1); | |
38 | |
39 % Construct Y from NegsBefore | |
40 Y = nan * ones(n,1); | |
41 Y((1:numPos) + NegsBefore) = Ipos; | |
42 Y(isnan(Y)) = Ineg; | |
43 | |
44 % Compute AUC loss for this ranking | |
45 Loss = 1 - sum(NegsBefore) / (numPos * numNeg * 2); | |
46 end | |
47 |