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