wolffd@0: function [deltas, idx, weights] = get_fo_deltas(r, X, rectify) wolffd@0: % [deltas, idx, (weights)] = get_fo_deltas(r, X) wolffd@0: % wolffd@0: % returns the difference vectors (dist(a,c) > dist(a,b)) wolffd@0: % for a given ranking: wolffd@0: % deltas{i}(:,1) = a - b, deltas{i}(:,2) = a - c; wolffd@0: % wolffd@0: % set rectify to output absolute values of training examples wolffd@0: wolffd@0: if nargin < 3 wolffd@0: rectify = 0; wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: this preallocation is not complete wolffd@0: % --- wolffd@0: deltas = {}; wolffd@0: idx = {}; wolffd@0: weights = []; wolffd@0: for i = 1:size(r,1) wolffd@0: wolffd@0: % feature index wolffd@0: a = i; wolffd@0: wolffd@0: % check if ranking is valid wolffd@0: if ~isempty(r{i,1}) && ~isempty(r{i,2})&& ... wolffd@0: isempty(intersect(r{i,1}, r{i,2})); wolffd@0: wolffd@0: % --- wolffd@0: % NOTE / TODO: the follwing is intended for compability wolffd@0: % both sides of the ranking may have more than one entry. wolffd@0: % for the MTT database, the ranking may be correct, but the wolffd@0: % inequalities build from non-singular rankings are not wolffd@0: % based on the actual data wolffd@0: % --- wolffd@0: for j = 1:numel(r{i,1}) wolffd@0: b = r{i,1}(j); wolffd@0: wolffd@0: for k = 1:numel(r{i,2}) wolffd@0: c = r{i,2}(k); wolffd@0: wolffd@0: % --- wolffd@0: % get vector deltas, wolffd@0: % NOTE: first: dissimilar, then similar pair wolffd@0: % --- wolffd@0: [dac] = X(:,a) - X(:,c); wolffd@0: [dab] = X(:,a) - X(:,b); wolffd@0: wolffd@0: if ~rectify wolffd@0: deltas{end+1} = [dac dab]; wolffd@0: else wolffd@0: % --- wolffd@0: % rectify the data for training wolffd@0: % --- wolffd@0: deltas{end+1} = abs([dac dab]); wolffd@0: end wolffd@0: wolffd@0: idx{end+1} = {[a c],[a b]}; wolffd@0: wolffd@0: % save weights wolffd@0: if size(r,2) == 3 wolffd@0: weights(end+1) = r{i,3}(1); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: