IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
splinedecomp.m
Go to the documentation of this file.
1 %>@ingroup maths
2 %>@file
3 %>@brief Spline decomposition
4 %>@code
5 %> [X_after]
6 %> [X_after, x_after]
7 %> [X_after, x_after, Basis] =
8 %> splinedecomp(X, x = [], no_basis, breaks, order = 6)
9 %>@endcode
10 %>
11 %> <h3>References</h3>
12 %> [1] J. Ramsay, G. Hooker, and S. Graves, Functional Data Analysis with R and MATLAB. New York: Springer, 2009.
13 %> Function @c create_bspline_basis
14 %> [2] Jim Ramsay, B. W. Silverman. Functional Data Analysis. 2nd Ed. Springer. 2005.
15 %
16 %> @param X
17 %> @param x
18 %> @param no_basis
19 %> @param breaks
20 %> @param order
21 function varargout = splinedecomp(X, x, no_basis, breaks, order)
22 
23 [no, nf] = size(X);
24 tt = 1:nf;
25 
26 if ~exist('order', 'var')
27  order = 6;
28 end;
29 if ~exist('breaks', 'var') || isempty(breaks)
30  breaks = linspace(1, nf, no_basis-order+2);
31 end;
32 
33 if ~exist('x', 'var') || isempty(x)
34  x = 1:nf;
35 end;
36 
37 bb = create_bspline_basis([1, nf], no_basis, order, round(breaks));
38 
39 % First makes a new x vector.
40 % It will contain the x-axis location where the splines peak
41 PREC = 1000; % This number only determines the precision and does not affect anything else.
42 tt2 = linspace(1, nf, PREC);
43 p = polyfit(tt, [data.fea_x], min(nf-1, 10)); % Gives a warning but who cares
44 x2 = polyval(p, tt2);
45 basismat = eval_basis(tt2, bb); % bases as columns
46 [vals, idxs] = max(basismat);
47 xx = x2(idxs);
48 
49 
50 % Now the main task
51 % We gotta get the loadings matrix
52 tt3 = 1:nf;
53 B = eval_basis(tt3, bb);
54 L = B*inv(B'*B); % L, the "loadings" matrix
55 
56 X = X*L;
57 
58 if nargout == 1
59  varargout = {X};
60 elseif nargout == 2
61  varargout = {X, xx};
62 elseif varargout == 3
63  varargout = {X, xx, B};
64 end;
65 
Analysis Session (AS) base class.
Definition: as.m:6
function splinedecomp(in X, in x, in no_basis, in breaks, in order)