annotate core/magnatagatune/ranking_from_comparison_trivial.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 [r, valididx, clip_ids] = ranking_from_comparison_trivial(comparison, comparison_ids)
wolffd@0 2 % returns a ranking for each of the compared songs
wolffd@0 3 %
wolffd@0 4 % r(idx,1) = all indexes which are similar to clip idx
wolffd@0 5 % r(idx,2) = all indexes which are dissimilar to clip idx
wolffd@0 6 %
wolffd@0 7 % if onlyvalid is set to true, only the transitive hull of
wolffd@0 8 % clips having sim and dissim values will be output
wolffd@0 9
wolffd@0 10 % ---
wolffd@0 11 % in comparison, the outlying piece is highlighted.
wolffd@0 12 % thus, we naively consider that
wolffd@0 13 % a. both of the remaining pieces are more similar to each other.
wolffd@0 14 % b. the outlier is dissimilar to both of the other pieces
wolffd@0 15 % ---
wolffd@0 16
wolffd@0 17 [outsort, outidx] = sort(comparison(:,4:6),2,'ascend');
wolffd@0 18
wolffd@0 19 r = cell(numel(comparison_ids), 2);
wolffd@0 20 s = zeros(numel(comparison_ids), 2); % score for rankings
wolffd@0 21 for i = 1:size(comparison, 1)
wolffd@0 22
wolffd@0 23 % get the three relevant comparison ids
wolffd@0 24
wolffd@0 25 pos = comparison(i, outidx(i,1:3));
wolffd@0 26 vals = outsort(i,:);
wolffd@0 27
wolffd@0 28 % ---
wolffd@0 29 % each of the three clips will be evaluated based on its position
wolffd@0 30 % the last clip is the potential outlyier
wolffd@0 31 % ---
wolffd@0 32
wolffd@0 33 % ---
wolffd@0 34 % usual case: two small values and a last outlie
wolffd@0 35 % ---
wolffd@0 36 if vals(2) ~= vals(3)
wolffd@0 37
wolffd@0 38
wolffd@0 39 % ---
wolffd@0 40 % first (most common) clip:
wolffd@0 41 % the second clip is more similar than the third one
wolffd@0 42 % ---
wolffd@0 43 r{pos(1),1} = cat(1, r{pos(1),1}, pos(2)); % similar
wolffd@0 44 r{pos(1),2} = cat(1, r{pos(1),2}, pos(3)); % dissimilar
wolffd@0 45 % else
wolffd@0 46 %
wolffd@0 47 % % ok, both seem more dissimilar to clip 1
wolffd@0 48 % r{pos(1),2} = cat(1, r{pos(1),1}, pos(2)); % both dissimilar
wolffd@0 49 % r{pos(1),2} = cat (1, r{pos(1),2}, pos(3)); % dissimilar
wolffd@0 50 end
wolffd@0 51
wolffd@0 52 if vals(3) ~= vals(1)
wolffd@0 53 % ---
wolffd@0 54 % the second clip is more similar to the first than
wolffd@0 55 % the third
wolffd@0 56 % ---
wolffd@0 57 r{pos(2),1} = cat(1, r{pos(2),1}, pos(1));
wolffd@0 58 r{pos(2),2} = cat(1, r{pos(2),2}, pos(3));
wolffd@0 59
wolffd@0 60 % ---
wolffd@0 61 % the third clip is not similar to any of the former
wolffd@0 62 % NOTE: we avoid this information as it possibly leads
wolffd@0 63 % to some contradictionary statements
wolffd@0 64 % ---
wolffd@0 65 r{pos(3),2} = cat(1, r{pos(3),2}, pos(1));
wolffd@0 66 r{pos(3),2} = cat(1, r{pos(3),2}, pos(2));
wolffd@0 67 end
wolffd@0 68
wolffd@0 69
wolffd@0 70 end
wolffd@0 71
wolffd@0 72 % ---
wolffd@0 73 % we cleanup r and
wolffd@0 74 % run basic checks on emptiness and paradox assumptions
wolffd@0 75 % ---
wolffd@0 76 valididx = zeros(size(r,1), 1);
wolffd@0 77 for i = 1:size(r, 1)
wolffd@0 78
wolffd@0 79 % make unique
wolffd@0 80 r{i,1} = unique(r{i,1});
wolffd@0 81 r{i,2} = unique(r{i,2});
wolffd@0 82
wolffd@0 83 % check
wolffd@0 84 valididx(i) = ~isempty(r{i,1}) && ~isempty(r{i,2}) && ...
wolffd@0 85 isempty(intersect(r{i,1}, r{i,2}));
wolffd@0 86 end
wolffd@0 87
wolffd@0 88 valididx = logical(valididx);
wolffd@0 89 clip_ids = 1:numel(comparison_ids);
wolffd@0 90