wolffd@0
|
1 function [sim, dissim, confidence] = sim_from_comparison_naive(comparison, comparison_ids, symmetrical)
|
wolffd@0
|
2 %
|
wolffd@0
|
3 % [sim, dissim, confidence] = sim_from_comparison_naive(comparison)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % derives symmetric, absolute similarity measurements
|
wolffd@0
|
6 % from relative magnatagatune comparisons
|
wolffd@0
|
7 % naive implementation for first tests of the ITML algorithm
|
wolffd@0
|
8 %
|
wolffd@0
|
9
|
wolffd@0
|
10 % reindex comparison for more simple evaluation
|
wolffd@0
|
11 % makro_prepare_comparison
|
wolffd@0
|
12
|
wolffd@0
|
13 % ---
|
wolffd@0
|
14 % analyse the number of comparisons for each pair of songs
|
wolffd@0
|
15 % ---
|
wolffd@0
|
16 [num_compares] = get_comparison_stats(comparison, comparison_ids);
|
wolffd@0
|
17
|
wolffd@0
|
18 % ---
|
wolffd@0
|
19 % in comparison, the outlying piece is highlighted.
|
wolffd@0
|
20 % thus, we naively consider that
|
wolffd@0
|
21 % a. both of the remaining pieces are more similar to each other.
|
wolffd@0
|
22 % b. the outlier is dissimilar to both of the other pieces
|
wolffd@0
|
23 % ---
|
wolffd@0
|
24 [outsort, outidx] = sort(comparison(:,4:6),2,'ascend');
|
wolffd@0
|
25
|
wolffd@0
|
26 % ---
|
wolffd@0
|
27 % similarity of the two non-outliers a, b
|
wolffd@0
|
28 % they are similar if both of them have scores way smaller
|
wolffd@0
|
29 % than the outlier c:
|
wolffd@0
|
30 % score (a,b) = 1 - (max(a,b)/c)
|
wolffd@0
|
31 %
|
wolffd@0
|
32 % dissimilarity: clip b is considered more different to clip c than
|
wolffd@0
|
33 % a, as clip a seems to share some properties with both songs
|
wolffd@0
|
34 % dissim(b,c) = 0.5 + b/(2c)
|
wolffd@0
|
35 % ---
|
wolffd@0
|
36
|
wolffd@0
|
37 sim = sparse(numel(comparison_ids),numel(comparison_ids));
|
wolffd@0
|
38 dissim = sparse(numel(comparison_ids),numel(comparison_ids));
|
wolffd@0
|
39 for i = 1:size(comparison,1)
|
wolffd@0
|
40
|
wolffd@0
|
41 % get the outlier votes
|
wolffd@0
|
42 simpair = comparison(i,outidx(i,1:2));
|
wolffd@0
|
43 c = comparison(i,outidx(i,3));
|
wolffd@0
|
44
|
wolffd@0
|
45 % we want a triangular similarity matrix
|
wolffd@0
|
46 [simpair, simidx] = sort(simpair);
|
wolffd@0
|
47 outsort(i,1:2) = outsort(i,simidx);
|
wolffd@0
|
48
|
wolffd@0
|
49 % ---
|
wolffd@0
|
50 % save the distance between the second biggest vote and the max vote.
|
wolffd@0
|
51 % NOTE: we bias the vote by dividing through the number of total
|
wolffd@0
|
52 % comparisons for the particular pair of clips
|
wolffd@0
|
53 % ---
|
wolffd@0
|
54 sim(simpair(1), simpair(2)) = sim(simpair(1), simpair(2)) + ...
|
wolffd@0
|
55 (1 - outsort(i,2) / outsort(i,3)) * (1 / num_compares(simpair(1),simpair(2)));
|
wolffd@0
|
56
|
wolffd@0
|
57 dissim(simpair(1:2), c) = 0.5 + (outsort(i,1:2) ./ (2 * outsort(i,3)));
|
wolffd@0
|
58 end
|
wolffd@0
|
59
|
wolffd@0
|
60 % ---
|
wolffd@0
|
61 % mirror to make matrix symmetrical
|
wolffd@0
|
62 % ---
|
wolffd@0
|
63 if nargin == 3 && symmetrical
|
wolffd@0
|
64 sim = sim + sim';
|
wolffd@0
|
65 dissim = dissim + dissim';
|
wolffd@0
|
66 end
|
wolffd@0
|
67
|
wolffd@0
|
68 % ---
|
wolffd@0
|
69 % TODO: use number of votes and std or similar to
|
wolffd@0
|
70 % rate the confidence for each similarity mesurement
|
wolffd@0
|
71 % ---
|
wolffd@0
|
72 confidence = [];
|
wolffd@0
|
73
|