annotate core/magnatagatune/ranking_from_comparison_Stober_all_constraints.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_Stober_all_constraints(comparison, comparison_ids)
wolffd@0 2 % returns rankings for compared songs.
wolffd@0 3 % rankings are genrerated using a Multigraph analysis of the comparison
wolffd@0 4 % data
wolffd@0 5 %
wolffd@0 6 % r(idx,1) = clip being similar to clip idx
wolffd@0 7 % r(idx,2) = clip being less similar to clip idx
wolffd@0 8 % r(idx,3) = weight of this ranking
wolffd@0 9 %
wolffd@0 10 % the indices in clipids correspond to the indices in comparison_ids
wolffd@0 11
wolffd@0 12 % create similarity graph
wolffd@0 13
wolffd@0 14 cprint(2, 'Generating Stober Multigraph for Similarity Constraints')
wolffd@0 15 % Gstob = ClipSimGraphStober();
wolffd@0 16 % Gstob.random_all_constraints_graph;
wolffd@0 17 % G = ClipSimGraphMulti(Gstob.to_DiGraph());
wolffd@0 18 load('comp_SimGraphStob_ac1.mat', 'G');
wolffd@0 19
wolffd@0 20
wolffd@0 21 % inverse comparison index
wolffd@0 22 inv_comparison = sparse(comparison_ids,1, 1:numel(comparison_ids));
wolffd@0 23
wolffd@0 24 % ---
wolffd@0 25 % derive similarity information: this
wolffd@0 26 % returns the weights of edges meaning sim(a,b) > sim(a,c)
wolffd@0 27 % ---
wolffd@0 28 [weights, a, b, c] = G.similarities();
wolffd@0 29 % ---
wolffd@0 30 % NOTE: it is yet unclear which index
wolffd@0 31 % (the comparison or the mtt clip index)
wolffd@0 32 % is best to use
wolffd@0 33 %
wolffd@0 34 % The lines below transform the MTT ids from the graph into comparison ids
wolffd@0 35 % ---
wolffd@0 36 a = inv_comparison(a);
wolffd@0 37 b = inv_comparison(b);
wolffd@0 38 c = inv_comparison(c);
wolffd@0 39
wolffd@0 40 % ---
wolffd@0 41 % reformat into ranking: the first 1019 clips are ordered
wolffd@0 42 % as in comparison_ids. then, clips mentioned more than once
wolffd@0 43 % are attached.
wolffd@0 44 % ---
wolffd@0 45 [a, idx] = sort(a);
wolffd@0 46 b = b(idx);
wolffd@0 47 c = c(idx);
wolffd@0 48
wolffd@0 49
wolffd@0 50 clip_ids = zeros(numel(a), 1);
wolffd@0 51
wolffd@0 52 % ---
wolffd@0 53 % NOTE: r may grow over its allocated size
wolffd@0 54 % ---
wolffd@0 55 r = cell(numel(a),1 );
wolffd@0 56
wolffd@0 57 % keep track of constraints which have been attached
wolffd@0 58 visited = zeros(1, numel(a));
wolffd@0 59 for i = 1:numel(comparison_ids)
wolffd@0 60
wolffd@0 61 % ---
wolffd@0 62 % get first occurence of this index,
wolffd@0 63 % and save the data into ranking
wolffd@0 64 % ---
wolffd@0 65 tmp_idx = find(a == i, 1, 'first');
wolffd@0 66
wolffd@0 67 clip_ids(i) = i; % == a(tmp_idx)
wolffd@0 68
wolffd@0 69 if ~isempty(tmp_idx)
wolffd@0 70 visited(tmp_idx) = true;
wolffd@0 71
wolffd@0 72 r{i,1} = b(tmp_idx);
wolffd@0 73 r{i,2} = c(tmp_idx);
wolffd@0 74 r{i,3} = weights(tmp_idx);
wolffd@0 75
wolffd@0 76 valididx(i) = true;
wolffd@0 77 else
wolffd@0 78 % invalid ranking
wolffd@0 79 valididx(i) = false;
wolffd@0 80 r{i,3} = 0;
wolffd@0 81 end
wolffd@0 82 end
wolffd@0 83
wolffd@0 84 % ---
wolffd@0 85 % Now we attach the remaining constraints
wolffd@0 86 % ---
wolffd@0 87 remaining = find(~visited);
wolffd@0 88 clip_ids( numel(comparison_ids)+1 : numel(comparison_ids)+numel(remaining)) = a(remaining);
wolffd@0 89
wolffd@0 90 for i = 1:numel(remaining)
wolffd@0 91 r{ numel(comparison_ids)+i, 1} = b(remaining(i));
wolffd@0 92 r{ numel(comparison_ids)+i , 2} = c(remaining(i));
wolffd@0 93 r{ numel(comparison_ids)+i , 3} = weights(remaining(i));
wolffd@0 94 end
wolffd@0 95
wolffd@0 96 valididx(numel(comparison_ids)+1 : ...
wolffd@0 97 numel(comparison_ids)+numel(remaining)) = true;
wolffd@0 98