wolffd@0: function [out, equal, singles, valid] = metric_fulfills_ranking(met, Y, clips) wolffd@0: % out = sim_fulfills_ranking(met, Y, ids) wolffd@0: % wolffd@0: % outputs (0-1) percentage of ranking constraints wolffd@0: % completely fulfilled by the given distance measure wolffd@0: wolffd@0: % --- wolffd@0: % for each valid query, check if the ranking is fulfilled wolffd@0: % we also count eeventswhere the distance is equal wolffd@0: % --- wolffd@0: valid = ~(cellfun(@isempty, Y(:,1)) | cellfun(@isempty, Y(:,2))); wolffd@0: wolffd@0: equal = 0; wolffd@0: singles = false(size(Y,1),1); wolffd@0: for i = 1:size(Y,1) wolffd@0: wolffd@0: if valid(i) wolffd@0: wolffd@0: if numel(Y{i,1}) == 1 && numel(Y{i,2}) == 1 wolffd@0: % --- wolffd@0: % Efficient singular ranking comparison wolffd@0: % using met.distance(clipa,clipb) wolffd@0: % --- wolffd@0: % NOTE: by using the < here, we loose half of the wolffd@0: % examples which have been same distance and wolffd@0: % randomly positioned in earlier runs :( wolffd@0: % --- wolffd@0: distgood = met.distance(clips(i), clips(Y{i,1})); wolffd@0: distbad = met.distance(clips(i), clips(Y{i,2})); wolffd@0: wolffd@0: singles(i) = distgood < distbad; wolffd@0: if distgood == distbad wolffd@0: equal = equal + 1; wolffd@0: end wolffd@0: else wolffd@0: % --- wolffd@0: % NOTE: Only reactivated for testing of wolffd@0: % outdated similarity data wolffd@0: % --- wolffd@0: wolffd@0: warning 'code only for outdated similarity data\n'; wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: this code is analogous to the above wolffd@0: % --- wolffd@0: singles(i) = 1; wolffd@0: for j=1:numel(Y{i,1}) wolffd@0: for k = 1:numel(Y{i,2}) wolffd@0: wolffd@0: % --- wolffd@0: % All the entries in Y(i,1) have to come before wolffd@0: % the ones in Y(i,2) wolffd@0: % --- wolffd@0: distgood = met.distance(clips(i), clips(Y{i,1}(j))); wolffd@0: distbad = met.distance(clips(i), clips(Y{i,2}(k))); wolffd@0: singles(i) = singles(i) && (distgood < distbad); wolffd@0: wolffd@0: % count equalities wolffd@0: if distgood == distbad wolffd@0: equal = equal + 1; wolffd@0: end wolffd@0: if ~singles(i) wolffd@0: break; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: end wolffd@0: else wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: out(1) = mean(singles(valid)); wolffd@0: if size(Y,2) == 3 wolffd@0: % --- wolffd@0: % weighted sum of singles: count satisfied votes wolffd@0: % --- wolffd@0: weights = cell2mat( Y( valid, 3)); wolffd@0: out(2) = sum(weights(singles(valid))) / sum(weights); wolffd@0: else wolffd@0: out(2) = -1; wolffd@0: end wolffd@0: out = out'; wolffd@0: wolffd@0: % markup invalid rankings wolffd@0: % singles(~valid) = -1; wolffd@0: wolffd@0: