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