IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
fcon_pca.m
Go to the documentation of this file.
1 %> @brief Principal Component Analysis
2 %>
3 %> @sa uip_fcon_pca.m
4 classdef fcon_pca < fcon_linear
5  properties
6  %> = 1: whether to rotate factors or not.
7  flag_rotate_factors = 0;
8  %> = 10: number of factors to feature in the transformed dataset.
9  no_factors = 10;
10  end;
11 
12  methods
13  function o = fcon_pca(o)
14  o.classtitle = 'Principal Component Analysis';
15  o.short = 'PCA';
16  o.flag_trainable = 1;
17  o.L_fea_prefix = 'PC';
18  end;
19  end;
20 
21  methods(Access=protected)
22 
23  function o = do_train(o, data)
24  if sum(var(data.X) < 1e-10) > 0
25  irverbose('WARNING: There are variables with variance lower than 1e-10, something may go wrong here!', 3);
26  end;
27 
28  V_star = princomp2(data.X);
29 
30  if o.no_factors > 0
31  no_factors_eff = min(o.no_factors, size(V_star, 2));
32  V_star = V_star(:, 1:no_factors_eff);
33  else
34  no_factors_eff = size(V_star, 2);
35  end;
36 
37  if o.flag_rotate_factors
38  V_star = rotatefactors2(V_star, 1);
39  end;
40 
41 
42  o.L = V_star;
43  o.L_fea_x = data.fea_x;
44  o.xname = data.xname;
45  o.xunit = data.xunit;
46  end;
47 
48  %> Overriden to imprint variance percentages in feature names
49  function data = do_use(o, data)
50  C = cov(data.X);
51  totalVar = sum(diag(C));
52  data = do_use@fcon_linear(o, data);
53  for i = 1:data.nf
54  varNow = var(data.X(:, i))/totalVar*100;
55  data.fea_names{i} = sprintf('%s%d (%.3g%%)', o.L_fea_prefix, data.fea_x(i), varNow);
56  end;
57  end;
58  end;
59 end
Principal Component Analysis.
Definition: fcon_pca.m:4
function irverbose(in s, in level)
Feature Construction - Linear Transformations base class.
Definition: fcon_linear.m:2
function rotatefactors2(in L, in flag_normal)
function princomp2(in X)