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