wolffd@0: % --- wolffd@0: % class ClipSimGraph wolffd@0: % Directed graph representing comparative clip similarities. wolffd@0: % wolffd@0: % each node represents a pair of clips, wolffd@0: % an edge (a,b) -> (a,c) is present if there is at least one wolffd@0: % users judging clip a more similar to clip b than to clip c wolffd@0: % wolffd@0: % The Edges thus represent the (are nearer to each othen than) wolffd@0: % expression wolffd@0: % --- wolffd@0: wolffd@0: classdef ClipSimGraph < ClipPairGraph wolffd@0: wolffd@0: % --- wolffd@0: % the methods wolffd@0: % --- wolffd@0: methods wolffd@0: wolffd@0: wolffd@0: % constructor of the graph wolffd@0: function G = ClipSimGraph(comparison, comparison_ids) wolffd@0: wolffd@0: % --- wolffd@0: % handle manual input wolffd@0: % --- wolffd@0: wolffd@0: if nargin == 1 wolffd@0: % --- wolffd@0: % this uses an imput grpaph wolffd@0: % to create a new MD graph wolffd@0: % --- wolffd@0: wolffd@0: G = ClipSimGraph(); wolffd@0: wolffd@0: % --- wolffd@0: % Add the input graph to the empty one wolffd@0: % --- wolffd@0: G.add_graph(comparison); wolffd@0: wolffd@0: % --- wolffd@0: % TODO: Copy Clip Pair Information if neccessary wolffd@0: % this is by now a handle copy wolffd@0: % --- wolffd@0: clas = cat(1, class(comparison), superclasses(comparison)); wolffd@0: if strcellfind(clas, 'ClipPairGraph') wolffd@0: wolffd@0: G.vid_map = comparison.vid_map; wolffd@0: end wolffd@0: wolffd@0: elseif nargin == 2 wolffd@0: wolffd@0: % --- wolffd@0: % handle automatic or manual input wolffd@0: % --- wolffd@0: for i = 1:size(comparison,1) wolffd@0: wolffd@0: % get clips and votes wolffd@0: clips = comparison_ids(comparison(i,1:3)); wolffd@0: votes = comparison(i,4:6); wolffd@0: wolffd@0: % for each triplet position create an edge reflecting the wolffd@0: % absolute and relative voting for this position wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: we index 0 - 2 to ease the mod wolffd@0: % calculaton for the remaining indices wolffd@0: % --- wolffd@0: for v = 0:2 wolffd@0: wolffd@0: % --- wolffd@0: % has at least one user voted this clip out? wolffd@0: % If so, treat it as an outlier and determine score wolffd@0: % --- wolffd@0: if votes(v+1) > 0 wolffd@0: wolffd@0: a = mod(v+1, 3)+1; wolffd@0: b = mod(v+2, 3)+1; wolffd@0: c = v+1; wolffd@0: wolffd@0: % --- wolffd@0: % TODO: how to determine the weight? wolffd@0: % There are two options: relative in the triple wolffd@0: % and counting absolute hits. wolffd@0: % first we go for the relative ones. wolffd@0: % The other is implemented in ClipSimGraphMulti wolffd@0: % --- wolffd@0: wolffd@0: % --- wolffd@0: % add an edge saying sim(a,b) > sim(a,c) wolffd@0: % --- wolffd@0: G.add_edge(clips(a), clips(b), clips(c), votes(c) / (sum(votes))); wolffd@0: wolffd@0: % --- wolffd@0: % every outlier vote results in two wolffd@0: % dissimilarity equations wolffd@0: % --- wolffd@0: wolffd@0: % edge 2 wolffd@0: G.add_edge(clips(b), clips(a), clips(c), votes(c) / (sum(votes))); wolffd@0: wolffd@0: end wolffd@0: wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: end wolffd@0: wolffd@0: % end constructor function wolffd@0: wolffd@0: wolffd@0: function [weights, a, b, c] = similarities(G) wolffd@0: % --- wolffd@0: % returns the weights of edges meaning sim(a,b) > sim(a,c) wolffd@0: % --- wolffd@0: % get edge weights wolffd@0: [weights, a, b, c] = edges(G); wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % add an edge saying sim(a,b) > sim(a,c) wolffd@0: % --- wolffd@0: % function add_edge(G, a, b, c, weight) wolffd@0: wolffd@0: function remove_edge(G, a, b, c) wolffd@0: wolffd@0: if nargin == 4 wolffd@0: V1 = add_node(G, a, b); wolffd@0: V2 = add_node(G, a, c); wolffd@0: wolffd@0: elseif nargin == 3 wolffd@0: V1 = a; wolffd@0: V2 = b; wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % call superclass wolffd@0: % --- wolffd@0: remove_edge@DiGraph(G, V1, V2); wolffd@0: end wolffd@0: wolffd@0: function set_edge(G, a, b, c, weight) wolffd@0: if nargin == 5 wolffd@0: V1 = add_node(G, a, b); wolffd@0: V2 = add_node(G, a, c); wolffd@0: wolffd@0: elseif nargin == 4 wolffd@0: V1 = a; wolffd@0: V2 = b; wolffd@0: weight = c; wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % call superclass wolffd@0: % --- wolffd@0: set_edge@DiGraph(G, V1, V2, weight); wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % simple mix of two sets of info about the same wolffd@0: % nodes: mean. wolffd@0: % NOTE: if there's more than two infos, the earlier wolffd@0: % information will loose influence wolffd@0: % --- wolffd@0: function join_edge(G, a, b, c, weight) wolffd@0: wolffd@0: if nargin == 5 wolffd@0: V1 = G.node(a, b); wolffd@0: V2 = G.node(a, c); wolffd@0: elseif nargin == 4 wolffd@0: V1 = a; wolffd@0: V2 = b; wolffd@0: weight = c; wolffd@0: end wolffd@0: wolffd@0: if G.edge(V1, V2) ~= 0 wolffd@0: wolffd@0: % set Edge to weight wolffd@0: G.E(V1, V2) = (G.E(V1, V2) + weight) /2; wolffd@0: wolffd@0: cprint(4, 'edge weight %d %d %d updated \n',a ,b , c) ; wolffd@0: else wolffd@0: wolffd@0: error 'nodes not found'; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: