wolffd@0: function [X, C, idx] = get_itml_deltas(r, in) wolffd@0: % [X, C, idx] = get_itml_deltas(r, in) wolffd@0: wolffd@0: %ITML Specs wolffd@0: % C: 4 column matrix wolffd@0: % column 1, 2: index of constrained points. Indexes between 1 and n wolffd@0: % column 3: 1 if points are similar, -1 if dissimilar wolffd@0: % column 4: right-hand side (lower or upper bound, depending on wolffd@0: % whether points are similar or dissimilar) wolffd@0: % wolffd@0: % X: (n x m) data matrix - each row corresponds to a single instance wolffd@0: % --- wolffd@0: % NOTE: X is thus input in transposed shape for the ITML algorithm wolffd@0: % --- wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: this preallocation is not complete wolffd@0: % --- wolffd@0: X = zeros(size(in,1), 0); wolffd@0: C = zeros(0,4); wolffd@0: idx = zeros(0,2); wolffd@0: wolffd@0: for i = 1:size(r,1) wolffd@0: wolffd@0: % feature indexing 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: % --- wolffd@0: [dab] = in(:,a) - in(:,b); wolffd@0: [dac] = in(:,a) - in(:,c); wolffd@0: wolffd@0: % --- wolffd@0: % save deltas in new feature matrix wolffd@0: % TODO: this method has duplicate entries wolffd@0: % if the pairs appear more than once wolffd@0: % index the data set and use more efficiently!!! wolffd@0: % --- wolffd@0: X = [X dab]; wolffd@0: idx(end+1,:) = [a b]; wolffd@0: iab = size(idx, 1); wolffd@0: wolffd@0: X = [X dac]; wolffd@0: idx(end+1,:) = [a c]; wolffd@0: iac = size(idx, 1); wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: wolffd@0: % in terms of the constraint, wolffd@0: % this should mean: dac - dab >= 1 wolffd@0: % wolffd@0: % 4th position cannot be 0, converges to Inf if > 1 wolffd@0: % -1,-1 learns the opposite of what constraitns say wolffd@0: % --- wolffd@0: C(end+1, :) = [iab iac -1 -1]; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % % --- wolffd@0: % % NOTE: here, we transpose the X for usage i nthe training wolffd@0: % % --- wolffd@0: % X = X'; wolffd@0: wolffd@0: end wolffd@0: