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