IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
quantile_landmarks.m
Go to the documentation of this file.
1 %>@ingroup maths
2 %>@file
3 %>@brief x-positions where quantiles occur.
4 %
5 %> @param I Obtained from an <code>integrate(X)</code>
6 %> @param par2 Number of quantiles, if a scalar, or the quantiles themselves (0 < value_i < 1), if a vector.
7 %> @param t_range for the final conversion of T's values to the proper scale. If not informed, it will be <code>[1, size(I, 2)]</code>
8 %> @return T
9 function T = quantile_landmarks(I, par2, t_range)
10 
11 [no, no_t] = size(I);
12 
13 if ~exist('t_range', 'var')
14  t_range = [1, no_t];
15 end;
16 
17 if length(par2) == 1
18  no_quants = par2;
19  quants = linspace(0, 1, no_quants+1);
20  quants = quants(2:end);
21 else
22  no_quants = length(par2);
23  quants = par2;
24 end;
25 
26 T = zeros(no, no_quants);
27 ii = 0;
28 for i = 1:no
29  j = 1;
30  vi = I(i, :)/I(i, end);
31 
32  % Interpolates the inverse of the integral function so now we'll be able to have a "quantile" function in functional
33  % form
34 
35  % attempt 0 (didn't work)
36 % % % % % % T(i, :) = spline(vi, 1:no_t, quants);
37 
38  % attempt 1 (bad fit)
39 % % % % % % p = polyfit(vi, 1:no_t, min(10, max(3, floor(no_t/20))));
40 % % % % % % T(i, :) = polyval(p, quants);
41 % % % % % % % Some bad interpolation in the begining can lead to tremendously negative numbers
42 % % % % % % wrong = T(i, :) < 1;
43 % % % % % % T(i, wrong) = 1;
44 % % % % % % if sum(T(i, :) > 1000) > 0
45 % % % % % % disp('porra, agora eh positivo!!!');
46 % % % % % % end;
47 % % % % %
48 
49 
50 
51 
52  % attempt 2 (good but uses the spline toolbox)
53  w = ones(1, length(vi)); w([1, end]) = 300;
54  sp = spaps(vi, 1:no_t, 1, w, 1); % perfect!!!
55  T(i, :) = fnval(sp, quants);
56 
57 
58  ii = ii+1;
59  if ii > 500
60  fprintf('. %g%%\n', i/no*100);
61  ii = 0;
62  end;
63 % i_quant = 1;
64 % while 1
65 % if vi(j) >= quants(i_quant)
66 % T(i, i_quant) = j;
67 % i_quant = i_quant+1;
68 % else
69 % j = j+1;
70 % end;
71 %
72 % if i_quant > no_quants
73 % break;
74 % end;
75 %
76 % if j > no_t
77 % irwarning('Maybe not monotonic');
78 % break;
79 % end;
80 % end;
81 end;
82 
83 tf = t_range(2);
84 ti = t_range(1);
85 
86 T = (T-1)*(tf-ti)/(no_t-1)+ti; % Normalizes warping information to the original number of features
function integrate(in X)