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