wolffd@0: function [r, valididx, clip_ids] = ranking_from_comparison_trivial(comparison, comparison_ids) wolffd@0: % returns a ranking for each of the compared songs wolffd@0: % wolffd@0: % r(idx,1) = all indexes which are similar to clip idx wolffd@0: % r(idx,2) = all indexes which are dissimilar to clip idx wolffd@0: % wolffd@0: % if onlyvalid is set to true, only the transitive hull of wolffd@0: % clips having sim and dissim values will be output wolffd@0: wolffd@0: % --- wolffd@0: % in comparison, the outlying piece is highlighted. wolffd@0: % thus, we naively consider that wolffd@0: % a. both of the remaining pieces are more similar to each other. wolffd@0: % b. the outlier is dissimilar to both of the other pieces wolffd@0: % --- wolffd@0: wolffd@0: [outsort, outidx] = sort(comparison(:,4:6),2,'ascend'); wolffd@0: wolffd@0: r = cell(numel(comparison_ids), 2); wolffd@0: s = zeros(numel(comparison_ids), 2); % score for rankings wolffd@0: for i = 1:size(comparison, 1) wolffd@0: wolffd@0: % get the three relevant comparison ids wolffd@0: wolffd@0: pos = comparison(i, outidx(i,1:3)); wolffd@0: vals = outsort(i,:); wolffd@0: wolffd@0: % --- wolffd@0: % each of the three clips will be evaluated based on its position wolffd@0: % the last clip is the potential outlyier wolffd@0: % --- wolffd@0: wolffd@0: % --- wolffd@0: % usual case: two small values and a last outlie wolffd@0: % --- wolffd@0: if vals(2) ~= vals(3) wolffd@0: wolffd@0: wolffd@0: % --- wolffd@0: % first (most common) clip: wolffd@0: % the second clip is more similar than the third one wolffd@0: % --- wolffd@0: r{pos(1),1} = cat(1, r{pos(1),1}, pos(2)); % similar wolffd@0: r{pos(1),2} = cat(1, r{pos(1),2}, pos(3)); % dissimilar wolffd@0: % else wolffd@0: % wolffd@0: % % ok, both seem more dissimilar to clip 1 wolffd@0: % r{pos(1),2} = cat(1, r{pos(1),1}, pos(2)); % both dissimilar wolffd@0: % r{pos(1),2} = cat (1, r{pos(1),2}, pos(3)); % dissimilar wolffd@0: end wolffd@0: wolffd@0: if vals(3) ~= vals(1) wolffd@0: % --- wolffd@0: % the second clip is more similar to the first than wolffd@0: % the third wolffd@0: % --- wolffd@0: r{pos(2),1} = cat(1, r{pos(2),1}, pos(1)); wolffd@0: r{pos(2),2} = cat(1, r{pos(2),2}, pos(3)); wolffd@0: wolffd@0: % --- wolffd@0: % the third clip is not similar to any of the former wolffd@0: % NOTE: we avoid this information as it possibly leads wolffd@0: % to some contradictionary statements wolffd@0: % --- wolffd@0: r{pos(3),2} = cat(1, r{pos(3),2}, pos(1)); wolffd@0: r{pos(3),2} = cat(1, r{pos(3),2}, pos(2)); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % we cleanup r and wolffd@0: % run basic checks on emptiness and paradox assumptions wolffd@0: % --- wolffd@0: valididx = zeros(size(r,1), 1); wolffd@0: for i = 1:size(r, 1) wolffd@0: wolffd@0: % make unique wolffd@0: r{i,1} = unique(r{i,1}); wolffd@0: r{i,2} = unique(r{i,2}); wolffd@0: wolffd@0: % check wolffd@0: valididx(i) = ~isempty(r{i,1}) && ~isempty(r{i,2}) && ... wolffd@0: isempty(intersect(r{i,1}, r{i,2})); wolffd@0: end wolffd@0: wolffd@0: valididx = logical(valididx); wolffd@0: clip_ids = 1:numel(comparison_ids); wolffd@0: