IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
fcon_spline.m
Go to the documentation of this file.
1 %> @brief B-Splines Decomposition
2 %
3 %> <h3>References</h3>
4 %> Ramsay JO. MATLAB, R and S-PLUS Functions for Functional Data Analysis. 2005:1-66.
5 %> ftp://ego.psych.mcgill.ca/pub/ramsay/FDAfuns/R/inst/Matlab/fdaM/FDAfuns.pdf
6 %> (Accessed on 10/Dec/2010)
7 %> @todo Should make the basis on training, not only use!
8 %>
9 %> @sa uip_fcon_spline.m
11  properties
12  %> Number of basis functions transformed dataset (default: 30).
13  no_basis = 30;
14  %> Breakpoints, given in x-axis indexes, in case one wants to fine-tune the splines (optional) (see reference).
15  breaks = [];
16  %> Splines order (default: 6) (see reference).
17  order = 6;
18  end;
19 
20  properties(SetAccess=protected)
21  %> New feature x-axis. See that this transformation keeps the x-axis unit!
22  fea_x_new;
23  end;
24 
25  methods
26  function o = fcon_spline()
27  o.classtitle = 'B-Splines Decomposition';
28  o.short = 'B-Splines';
29  o.flag_trainable = 1;
30  end;
31  end;
32 
33  methods(Access=protected)
34  function o = do_train(o, data)
35  if isempty(o.breaks)
36  bb = create_bspline_basis([1, data.nf], o.no_basis, o.order);
37  else
38  bb = create_bspline_basis([1, data.nf], o.no_basis, o.order, round(o.breaks));
39  end;
40 
41  % First makes a new x vector.
42  % It will contain the x-axis location where the splines peak
43  PREC = 1000; % This number only determines the precision and does not affect anything else.
44  tt = 1:data.nf;
45  tt2 = linspace(1, data.nf, PREC);
46  warning off;
47  p = polyfit(tt, [data.fea_x], min(data.nf-1, 10));
48  warning off;
49  x2 = polyval(p, tt2);
50  basismat = eval_basis(tt2, bb); % bases as columns
51  [vals, idxs] = max(basismat);
52  o.fea_x_new = x2(idxs);
53 
54 
55  % Now the main task
56  % We gotta get the loadings matrix
57  tt3 = 1:data.nf;
58  B = eval_basis(tt3, bb);
59  o.L = B/(B'*B); % L, the "loadings" matrix calculated by Least-Squares
60  o.L_fea_x = data.fea_x;
61  o.xname = data.xname;
62  o.xunit = data.xunit;
63  end;
64 
65  function data = do_use(o, data)
66  data = data.transform_linear(o.L, o.L_fea_prefix);
67  data.fea_x = o.fea_x_new;
68  end;
69  end;
70 end
Feature Construction - Linear Transformations base class.
Definition: fcon_linear.m:2
B-Splines Decomposition.
Definition: fcon_spline.m:10
Analysis Session (AS) base class.
Definition: as.m:6