Mercurial > hg > camir-aes2014
comparison core/tools/machine_learning/get_itml_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 [X, C, idx] = get_itml_deltas(r, in) | |
2 % [X, C, idx] = get_itml_deltas(r, in) | |
3 | |
4 %ITML Specs | |
5 % C: 4 column matrix | |
6 % column 1, 2: index of constrained points. Indexes between 1 and n | |
7 % column 3: 1 if points are similar, -1 if dissimilar | |
8 % column 4: right-hand side (lower or upper bound, depending on | |
9 % whether points are similar or dissimilar) | |
10 % | |
11 % X: (n x m) data matrix - each row corresponds to a single instance | |
12 % --- | |
13 % NOTE: X is thus input in transposed shape for the ITML algorithm | |
14 % --- | |
15 | |
16 % --- | |
17 % NOTE: this preallocation is not complete | |
18 % --- | |
19 X = zeros(size(in,1), 0); | |
20 C = zeros(0,4); | |
21 idx = zeros(0,2); | |
22 | |
23 for i = 1:size(r,1) | |
24 | |
25 % feature indexing | |
26 a = i; | |
27 | |
28 % check if ranking is valid | |
29 if ~isempty(r{i,1}) && ~isempty(r{i,2})&& ... | |
30 isempty(intersect(r{i,1}, r{i,2})); | |
31 | |
32 % --- | |
33 % NOTE / TODO: the follwing is intended for compability | |
34 % both sides of the ranking may have more than one entry. | |
35 % for the MTT database, the ranking may be correct, but the | |
36 % inequalities build from non-singular rankings are not | |
37 % based on the actual data | |
38 % --- | |
39 for j = 1:numel(r{i,1}) | |
40 b = r{i,1}(j); | |
41 | |
42 for k = 1:numel(r{i,2}) | |
43 c = r{i,2}(k); | |
44 | |
45 % --- | |
46 % get vector deltas | |
47 % --- | |
48 [dab] = in(:,a) - in(:,b); | |
49 [dac] = in(:,a) - in(:,c); | |
50 | |
51 % --- | |
52 % save deltas in new feature matrix | |
53 % TODO: this method has duplicate entries | |
54 % if the pairs appear more than once | |
55 % index the data set and use more efficiently!!! | |
56 % --- | |
57 X = [X dab]; | |
58 idx(end+1,:) = [a b]; | |
59 iab = size(idx, 1); | |
60 | |
61 X = [X dac]; | |
62 idx(end+1,:) = [a c]; | |
63 iac = size(idx, 1); | |
64 | |
65 % --- | |
66 % NOTE: | |
67 % in terms of the constraint, | |
68 % this should mean: dac - dab >= 1 | |
69 % | |
70 % 4th position cannot be 0, converges to Inf if > 1 | |
71 % -1,-1 learns the opposite of what constraitns say | |
72 % --- | |
73 C(end+1, :) = [iab iac -1 -1]; | |
74 end | |
75 end | |
76 end | |
77 end | |
78 | |
79 % % --- | |
80 % % NOTE: here, we transpose the X for usage i nthe training | |
81 % % --- | |
82 % X = X'; | |
83 | |
84 end | |
85 |