annotate core/magnatagatune/metric_fulfills_ranking.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [out, equal, singles, valid] = metric_fulfills_ranking(met, Y, clips)
wolffd@0 2 % out = sim_fulfills_ranking(met, Y, ids)
wolffd@0 3 %
wolffd@0 4 % outputs (0-1) percentage of ranking constraints
wolffd@0 5 % completely fulfilled by the given distance measure
wolffd@0 6
wolffd@0 7 % ---
wolffd@0 8 % for each valid query, check if the ranking is fulfilled
wolffd@0 9 % we also count eeventswhere the distance is equal
wolffd@0 10 % ---
wolffd@0 11 valid = ~(cellfun(@isempty, Y(:,1)) | cellfun(@isempty, Y(:,2)));
wolffd@0 12
wolffd@0 13 equal = 0;
wolffd@0 14 singles = false(size(Y,1),1);
wolffd@0 15 for i = 1:size(Y,1)
wolffd@0 16
wolffd@0 17 if valid(i)
wolffd@0 18
wolffd@0 19 if numel(Y{i,1}) == 1 && numel(Y{i,2}) == 1
wolffd@0 20 % ---
wolffd@0 21 % Efficient singular ranking comparison
wolffd@0 22 % using met.distance(clipa,clipb)
wolffd@0 23 % ---
wolffd@0 24 % NOTE: by using the < here, we loose half of the
wolffd@0 25 % examples which have been same distance and
wolffd@0 26 % randomly positioned in earlier runs :(
wolffd@0 27 % ---
wolffd@0 28 distgood = met.distance(clips(i), clips(Y{i,1}));
wolffd@0 29 distbad = met.distance(clips(i), clips(Y{i,2}));
wolffd@0 30
wolffd@0 31 singles(i) = distgood < distbad;
wolffd@0 32 if distgood == distbad
wolffd@0 33 equal = equal + 1;
wolffd@0 34 end
wolffd@0 35 else
wolffd@0 36 % ---
wolffd@0 37 % NOTE: Only reactivated for testing of
wolffd@0 38 % outdated similarity data
wolffd@0 39 % ---
wolffd@0 40
wolffd@0 41 warning 'code only for outdated similarity data\n';
wolffd@0 42
wolffd@0 43 % ---
wolffd@0 44 % NOTE: this code is analogous to the above
wolffd@0 45 % ---
wolffd@0 46 singles(i) = 1;
wolffd@0 47 for j=1:numel(Y{i,1})
wolffd@0 48 for k = 1:numel(Y{i,2})
wolffd@0 49
wolffd@0 50 % ---
wolffd@0 51 % All the entries in Y(i,1) have to come before
wolffd@0 52 % the ones in Y(i,2)
wolffd@0 53 % ---
wolffd@0 54 distgood = met.distance(clips(i), clips(Y{i,1}(j)));
wolffd@0 55 distbad = met.distance(clips(i), clips(Y{i,2}(k)));
wolffd@0 56 singles(i) = singles(i) && (distgood < distbad);
wolffd@0 57
wolffd@0 58 % count equalities
wolffd@0 59 if distgood == distbad
wolffd@0 60 equal = equal + 1;
wolffd@0 61 end
wolffd@0 62 if ~singles(i)
wolffd@0 63 break;
wolffd@0 64 end
wolffd@0 65 end
wolffd@0 66 end
wolffd@0 67
wolffd@0 68
wolffd@0 69 end
wolffd@0 70 else
wolffd@0 71 end
wolffd@0 72 end
wolffd@0 73
wolffd@0 74
wolffd@0 75 out(1) = mean(singles(valid));
wolffd@0 76 if size(Y,2) == 3
wolffd@0 77 % ---
wolffd@0 78 % weighted sum of singles: count satisfied votes
wolffd@0 79 % ---
wolffd@0 80 weights = cell2mat( Y( valid, 3));
wolffd@0 81 out(2) = sum(weights(singles(valid))) / sum(weights);
wolffd@0 82 else
wolffd@0 83 out(2) = -1;
wolffd@0 84 end
wolffd@0 85 out = out';
wolffd@0 86
wolffd@0 87 % markup invalid rankings
wolffd@0 88 % singles(~valid) = -1;
wolffd@0 89
wolffd@0 90