Mercurial > hg > camir-aes2014
comparison core/magnatagatune/ClipSimGraph.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 % --- | |
2 % class ClipSimGraph | |
3 % Directed graph representing comparative clip similarities. | |
4 % | |
5 % each node represents a pair of clips, | |
6 % an edge (a,b) -> (a,c) is present if there is at least one | |
7 % users judging clip a more similar to clip b than to clip c | |
8 % | |
9 % The Edges thus represent the (are nearer to each othen than) | |
10 % expression | |
11 % --- | |
12 | |
13 classdef ClipSimGraph < ClipPairGraph | |
14 | |
15 % --- | |
16 % the methods | |
17 % --- | |
18 methods | |
19 | |
20 | |
21 % constructor of the graph | |
22 function G = ClipSimGraph(comparison, comparison_ids) | |
23 | |
24 % --- | |
25 % handle manual input | |
26 % --- | |
27 | |
28 if nargin == 1 | |
29 % --- | |
30 % this uses an imput grpaph | |
31 % to create a new MD graph | |
32 % --- | |
33 | |
34 G = ClipSimGraph(); | |
35 | |
36 % --- | |
37 % Add the input graph to the empty one | |
38 % --- | |
39 G.add_graph(comparison); | |
40 | |
41 % --- | |
42 % TODO: Copy Clip Pair Information if neccessary | |
43 % this is by now a handle copy | |
44 % --- | |
45 clas = cat(1, class(comparison), superclasses(comparison)); | |
46 if strcellfind(clas, 'ClipPairGraph') | |
47 | |
48 G.vid_map = comparison.vid_map; | |
49 end | |
50 | |
51 elseif nargin == 2 | |
52 | |
53 % --- | |
54 % handle automatic or manual input | |
55 % --- | |
56 for i = 1:size(comparison,1) | |
57 | |
58 % get clips and votes | |
59 clips = comparison_ids(comparison(i,1:3)); | |
60 votes = comparison(i,4:6); | |
61 | |
62 % for each triplet position create an edge reflecting the | |
63 % absolute and relative voting for this position | |
64 | |
65 % --- | |
66 % NOTE: we index 0 - 2 to ease the mod | |
67 % calculaton for the remaining indices | |
68 % --- | |
69 for v = 0:2 | |
70 | |
71 % --- | |
72 % has at least one user voted this clip out? | |
73 % If so, treat it as an outlier and determine score | |
74 % --- | |
75 if votes(v+1) > 0 | |
76 | |
77 a = mod(v+1, 3)+1; | |
78 b = mod(v+2, 3)+1; | |
79 c = v+1; | |
80 | |
81 % --- | |
82 % TODO: how to determine the weight? | |
83 % There are two options: relative in the triple | |
84 % and counting absolute hits. | |
85 % first we go for the relative ones. | |
86 % The other is implemented in ClipSimGraphMulti | |
87 % --- | |
88 | |
89 % --- | |
90 % add an edge saying sim(a,b) > sim(a,c) | |
91 % --- | |
92 G.add_edge(clips(a), clips(b), clips(c), votes(c) / (sum(votes))); | |
93 | |
94 % --- | |
95 % every outlier vote results in two | |
96 % dissimilarity equations | |
97 % --- | |
98 | |
99 % edge 2 | |
100 G.add_edge(clips(b), clips(a), clips(c), votes(c) / (sum(votes))); | |
101 | |
102 end | |
103 | |
104 end | |
105 end | |
106 end | |
107 | |
108 end | |
109 | |
110 % end constructor function | |
111 | |
112 | |
113 function [weights, a, b, c] = similarities(G) | |
114 % --- | |
115 % returns the weights of edges meaning sim(a,b) > sim(a,c) | |
116 % --- | |
117 % get edge weights | |
118 [weights, a, b, c] = edges(G); | |
119 end | |
120 | |
121 % --- | |
122 % add an edge saying sim(a,b) > sim(a,c) | |
123 % --- | |
124 % function add_edge(G, a, b, c, weight) | |
125 | |
126 function remove_edge(G, a, b, c) | |
127 | |
128 if nargin == 4 | |
129 V1 = add_node(G, a, b); | |
130 V2 = add_node(G, a, c); | |
131 | |
132 elseif nargin == 3 | |
133 V1 = a; | |
134 V2 = b; | |
135 end | |
136 | |
137 % --- | |
138 % call superclass | |
139 % --- | |
140 remove_edge@DiGraph(G, V1, V2); | |
141 end | |
142 | |
143 function set_edge(G, a, b, c, weight) | |
144 if nargin == 5 | |
145 V1 = add_node(G, a, b); | |
146 V2 = add_node(G, a, c); | |
147 | |
148 elseif nargin == 4 | |
149 V1 = a; | |
150 V2 = b; | |
151 weight = c; | |
152 end | |
153 | |
154 % --- | |
155 % call superclass | |
156 % --- | |
157 set_edge@DiGraph(G, V1, V2, weight); | |
158 end | |
159 | |
160 % --- | |
161 % simple mix of two sets of info about the same | |
162 % nodes: mean. | |
163 % NOTE: if there's more than two infos, the earlier | |
164 % information will loose influence | |
165 % --- | |
166 function join_edge(G, a, b, c, weight) | |
167 | |
168 if nargin == 5 | |
169 V1 = G.node(a, b); | |
170 V2 = G.node(a, c); | |
171 elseif nargin == 4 | |
172 V1 = a; | |
173 V2 = b; | |
174 weight = c; | |
175 end | |
176 | |
177 if G.edge(V1, V2) ~= 0 | |
178 | |
179 % set Edge to weight | |
180 G.E(V1, V2) = (G.E(V1, V2) + weight) /2; | |
181 | |
182 cprint(4, 'edge weight %d %d %d updated \n',a ,b , c) ; | |
183 else | |
184 | |
185 error 'nodes not found'; | |
186 end | |
187 end | |
188 end | |
189 end | |
190 | |
191 |