Daniel@0: function [Y, Loss] = separationOracleAUC(q, D, pos, neg, k) Daniel@0: % Daniel@0: % [Y,Loss] = separationOracleAUC(q, D, pos, neg, k) Daniel@0: % Daniel@0: % q = index of the query point Daniel@0: % D = the current distance matrix Daniel@0: % pos = indices of relevant results for q Daniel@0: % neg = indices of irrelevant results for q Daniel@0: % k = length of the list to consider (unused in AUC) Daniel@0: % Daniel@0: % Y is a permutation 1:n corresponding to the maximally Daniel@0: % violated constraint Daniel@0: % Daniel@0: % Loss is the loss for Y, in this case, 1-AUC(Y) Daniel@0: Daniel@0: Daniel@0: % First, sort the documents in descending order of W'Phi(q,x) Daniel@0: % Phi = - (X(q) - X(x)) * (X(q) - X(x))' Daniel@0: Daniel@0: % Sort the positive documents Daniel@0: ScorePos = - D(pos,q); Daniel@0: [Vpos, Ipos] = sort(full(ScorePos'), 'descend'); Daniel@0: Ipos = pos(Ipos); Daniel@0: Daniel@0: % Sort the negative documents Daniel@0: ScoreNeg = - D(neg,q); Daniel@0: [Vneg, Ineg] = sort(full(ScoreNeg'), 'descend'); Daniel@0: Ineg = neg(Ineg); Daniel@0: Daniel@0: Daniel@0: % How many pos and neg documents are we using here? Daniel@0: numPos = length(pos); Daniel@0: numNeg = length(neg); Daniel@0: n = numPos + numNeg; Daniel@0: Daniel@0: Daniel@0: NegsBefore = sum(bsxfun(@lt, Vpos, Vneg' + 0.5),1); Daniel@0: Daniel@0: % Construct Y from NegsBefore Daniel@0: Y = nan * ones(n,1); Daniel@0: Y((1:numPos) + NegsBefore) = Ipos; Daniel@0: Y(isnan(Y)) = Ineg; Daniel@0: Daniel@0: % Compute AUC loss for this ranking Daniel@0: Loss = 1 - sum(NegsBefore) / (numPos * numNeg * 2); Daniel@0: end Daniel@0: