annotate toolboxes/distance_learning/mlr/separationOracle/separationOracleAUC.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [Y, Loss] = separationOracleAUC(q, D, pos, neg, k)
Daniel@0 2 %
Daniel@0 3 % [Y,Loss] = separationOracleAUC(q, D, pos, neg, k)
Daniel@0 4 %
Daniel@0 5 % q = index of the query point
Daniel@0 6 % D = the current distance matrix
Daniel@0 7 % pos = indices of relevant results for q
Daniel@0 8 % neg = indices of irrelevant results for q
Daniel@0 9 % k = length of the list to consider (unused in AUC)
Daniel@0 10 %
Daniel@0 11 % Y is a permutation 1:n corresponding to the maximally
Daniel@0 12 % violated constraint
Daniel@0 13 %
Daniel@0 14 % Loss is the loss for Y, in this case, 1-AUC(Y)
Daniel@0 15
Daniel@0 16
Daniel@0 17 % First, sort the documents in descending order of W'Phi(q,x)
Daniel@0 18 % Phi = - (X(q) - X(x)) * (X(q) - X(x))'
Daniel@0 19
Daniel@0 20 % Sort the positive documents
Daniel@0 21 ScorePos = - D(pos,q);
Daniel@0 22 [Vpos, Ipos] = sort(full(ScorePos'), 'descend');
Daniel@0 23 Ipos = pos(Ipos);
Daniel@0 24
Daniel@0 25 % Sort the negative documents
Daniel@0 26 ScoreNeg = - D(neg,q);
Daniel@0 27 [Vneg, Ineg] = sort(full(ScoreNeg'), 'descend');
Daniel@0 28 Ineg = neg(Ineg);
Daniel@0 29
Daniel@0 30
Daniel@0 31 % How many pos and neg documents are we using here?
Daniel@0 32 numPos = length(pos);
Daniel@0 33 numNeg = length(neg);
Daniel@0 34 n = numPos + numNeg;
Daniel@0 35
Daniel@0 36
Daniel@0 37 NegsBefore = sum(bsxfun(@lt, Vpos, Vneg' + 0.5),1);
Daniel@0 38
Daniel@0 39 % Construct Y from NegsBefore
Daniel@0 40 Y = nan * ones(n,1);
Daniel@0 41 Y((1:numPos) + NegsBefore) = Ipos;
Daniel@0 42 Y(isnan(Y)) = Ineg;
Daniel@0 43
Daniel@0 44 % Compute AUC loss for this ranking
Daniel@0 45 Loss = 1 - sum(NegsBefore) / (numPos * numNeg * 2);
Daniel@0 46 end
Daniel@0 47