annotate core/tools/machine_learning/get_fo_deltas.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 function [deltas, idx, weights] = get_fo_deltas(r, X, rectify)
wolffd@0 2 % [deltas, idx, (weights)] = get_fo_deltas(r, X)
wolffd@0 3 %
wolffd@0 4 % returns the difference vectors (dist(a,c) > dist(a,b))
wolffd@0 5 % for a given ranking:
wolffd@0 6 % deltas{i}(:,1) = a - b, deltas{i}(:,2) = a - c;
wolffd@0 7 %
wolffd@0 8 % set rectify to output absolute values of training examples
wolffd@0 9
wolffd@0 10 if nargin < 3
wolffd@0 11 rectify = 0;
wolffd@0 12 end
wolffd@0 13
wolffd@0 14 % ---
wolffd@0 15 % NOTE: this preallocation is not complete
wolffd@0 16 % ---
wolffd@0 17 deltas = {};
wolffd@0 18 idx = {};
wolffd@0 19 weights = [];
wolffd@0 20 for i = 1:size(r,1)
wolffd@0 21
wolffd@0 22 % feature index
wolffd@0 23 a = i;
wolffd@0 24
wolffd@0 25 % check if ranking is valid
wolffd@0 26 if ~isempty(r{i,1}) && ~isempty(r{i,2})&& ...
wolffd@0 27 isempty(intersect(r{i,1}, r{i,2}));
wolffd@0 28
wolffd@0 29 % ---
wolffd@0 30 % NOTE / TODO: the follwing is intended for compability
wolffd@0 31 % both sides of the ranking may have more than one entry.
wolffd@0 32 % for the MTT database, the ranking may be correct, but the
wolffd@0 33 % inequalities build from non-singular rankings are not
wolffd@0 34 % based on the actual data
wolffd@0 35 % ---
wolffd@0 36 for j = 1:numel(r{i,1})
wolffd@0 37 b = r{i,1}(j);
wolffd@0 38
wolffd@0 39 for k = 1:numel(r{i,2})
wolffd@0 40 c = r{i,2}(k);
wolffd@0 41
wolffd@0 42 % ---
wolffd@0 43 % get vector deltas,
wolffd@0 44 % NOTE: first: dissimilar, then similar pair
wolffd@0 45 % ---
wolffd@0 46 [dac] = X(:,a) - X(:,c);
wolffd@0 47 [dab] = X(:,a) - X(:,b);
wolffd@0 48
wolffd@0 49 if ~rectify
wolffd@0 50 deltas{end+1} = [dac dab];
wolffd@0 51 else
wolffd@0 52 % ---
wolffd@0 53 % rectify the data for training
wolffd@0 54 % ---
wolffd@0 55 deltas{end+1} = abs([dac dab]);
wolffd@0 56 end
wolffd@0 57
wolffd@0 58 idx{end+1} = {[a c],[a b]};
wolffd@0 59
wolffd@0 60 % save weights
wolffd@0 61 if size(r,2) == 3
wolffd@0 62 weights(end+1) = r{i,3}(1);
wolffd@0 63 end
wolffd@0 64 end
wolffd@0 65 end
wolffd@0 66 end
wolffd@0 67 end
wolffd@0 68 end
wolffd@0 69