annotate core/tools/machine_learning/get_fo_deltas.m @ 0:cc4b1211e677 tip

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