Mercurial > hg > camir-aes2014
comparison core/magnatagatune/ClipSimGraphMulti.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 ClipSimGraphMulti | |
3 % Directed MultiGraph representing comparative clip similarities. | |
4 % EACH pair of vertices has multiple directed edges connecting them | |
5 % | |
6 % each node represents a pair of clips, | |
7 % an edge (a,b) -> (a,c) is present if there is at least one | |
8 % users judging clip a more similar to clip b than to clip c | |
9 % | |
10 % Each edge thus represent a single (are nearer to each othen than) | |
11 % expression | |
12 % --- | |
13 | |
14 classdef ClipSimGraphMulti < ClipSimGraph & handle | |
15 | |
16 | |
17 properties | |
18 | |
19 end | |
20 | |
21 % --- | |
22 % the methods | |
23 % --- | |
24 methods | |
25 | |
26 % constructor of the graph | |
27 function G = ClipSimGraphMulti(comparison, comparison_ids) | |
28 | |
29 if nargin == 0 | |
30 % --- | |
31 % empty constructor | |
32 % --- | |
33 | |
34 elseif nargin == 1 | |
35 % todo: copy graph if same class | |
36 | |
37 % --- | |
38 % this uses an imput grpaph | |
39 % to create a new MD graph | |
40 % --- | |
41 | |
42 G = ClipSimGraphMulti(); | |
43 | |
44 % --- | |
45 % Add the input graph to the empty one | |
46 % --- | |
47 G.add_graph(comparison); | |
48 | |
49 elseif nargin == 2 | |
50 | |
51 | |
52 % --- | |
53 % handle automatic or manual input | |
54 % --- | |
55 for i = 1:size(comparison,1) | |
56 | |
57 % get clips and votes | |
58 clips = comparison_ids(comparison(i,1:3)); | |
59 votes = comparison(i,4:6); | |
60 | |
61 % for each triplet position create an edge reflecting the | |
62 % absolute and relative voting for this position | |
63 | |
64 % --- | |
65 % NOTE: we index 0 - 2 to ease the mod | |
66 % calculaton for the remaining indices | |
67 % --- | |
68 for v = 0:2 | |
69 | |
70 % --- | |
71 % has at least one user voted this clip out? | |
72 % If so, treat it as an outlier and determine score | |
73 % --- | |
74 if votes(v+1) > 0 | |
75 | |
76 a = mod(v+1, 3)+1; | |
77 b = mod(v+2, 3)+1; | |
78 c = v+1; | |
79 | |
80 | |
81 % --- | |
82 % every outlier vote results in two | |
83 % dissimilarity equations, favored by | |
84 % the people who voted for the outlier | |
85 % --- | |
86 | |
87 % edge 1 | |
88 add_edge(G, clips(a), clips(b), clips(c), votes(v+1)); | |
89 | |
90 % edge 2 | |
91 add_edge(G, clips(b), clips(a), clips(c), votes(v+1)); | |
92 end | |
93 end | |
94 | |
95 end | |
96 end | |
97 | |
98 % end constructor function | |
99 end | |
100 | |
101 function out = order(G) | |
102 | |
103 out = sum(G.V); | |
104 end | |
105 | |
106 function out = num_edges_multi(G) | |
107 out = sum(sum(G.E)); | |
108 end | |
109 | |
110 function out = num_edges(G) | |
111 out = sum(sum(G.E ~= 0)); | |
112 end | |
113 | |
114 | |
115 % --- | |
116 % NOTE: the weight explains the multiplicity of each | |
117 % edge, to correctily describe this, | |
118 % we just count the votes | |
119 % --- | |
120 function join_edge(G, a, b, c, weight) | |
121 | |
122 if nargin == 5 | |
123 V1 = G.node(a, b); | |
124 V2 = G.node(a, c); | |
125 elseif nargin == 4 | |
126 V1 = a; | |
127 V2 = b; | |
128 weight = c; | |
129 end | |
130 | |
131 if G.edge(V1, V2) ~= 0 | |
132 | |
133 % set add number to Edge index | |
134 G.E(V1, V2) = (G.E(V1, V2) + weight); | |
135 | |
136 cprint(3, 'edge weight %d %d %d updated \n',a ,b , c) ; | |
137 else | |
138 | |
139 error 'nodes not found'; | |
140 end | |
141 end | |
142 | |
143 % --- | |
144 % This eliminates any order-2 cycles, | |
145 % by substracting opposing edge counts | |
146 % --- | |
147 function remove_cycles_length2(G) | |
148 | |
149 G.E = max(0, G.E - G.E'); | |
150 end | |
151 % --- | |
152 % TODO: this back-and forth transform is a workaround | |
153 % avoiding some costly other transformation which would | |
154 % happen during the direct digraph call | |
155 % --- | |
156 | |
157 function [Gs, s, id] = connected_components(G, varargin) | |
158 % --- | |
159 % get all connected subgraphs: | |
160 % --- | |
161 G2 = DiGraph(G); | |
162 | |
163 [GsDiGraph, s, id] = connected_components@DiGraph(G2, varargin{:}); | |
164 | |
165 for i = 1:numel(GsDiGraph) | |
166 Gs(i) = ClipSimGraphMulti(GsDiGraph(i)); | |
167 end | |
168 end | |
169 | |
170 | |
171 end | |
172 | |
173 methods (Hidden) | |
174 | |
175 end | |
176 end |