IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
data_get_cv.m
Go to the documentation of this file.
1 %>@ingroup datasettools
2 %> @file
3 %> @brief Calculates the "cluster vectors"
4 %>
5 %> <h3>References</h3>
6 %> (1) Binary Mixture Effects by PBDE Congeners (47, 153, 183, or 209) and PCB Congeners (126 or 153) in MCF-7 Cells:
7 %> Biochemical Alterations Assessed by IR Spectroscopy and Multivariate Analysis. Valon Llabjani, Julio Trevisan,
8 %> Kevin C. Jones, Richard F. Shore, Francis L. Martin. ES&T, 2010, 44 (10), 3992-3998.
9 %>
10 %> (2) Martin FL, German MJ, Wit E, et al. Identifying variables responsible for clustering in discriminant analysis of
11 %> data from infrared microspectroscopy of a biological sample. J. Comp. Biol. 2007; 14(9):1176-84.
12 
13 %> @param data @ref irdata object. Input dataset. This dataset is transformed into the L/factor space, then the average spectrum for each class
14 %> is calculated. The vectors stretched in the factor space between (the origin / the average of a reference class) and (the average
15 %> of a target class) become the coefficients of a linear combination of the columns of L to give the cluster vectors.
16 %> @attention If <code>idx_class_origin <= 0</code>, @c data <b>will be mean-centered</b>
17 %> @param L Loadings matrix
18 %> @param idx_class_origin Index of class to be considered the origin of the space (1). If <= 0, classical cluster
19 %> vectors will be calculated (2), i.e., the cluster vectors origin is the origin of the space.
20 %>
21 %> @return \em cv Cluster vectors, dimensions [\ref nf]x[\ref nc]
22 function cv = data_get_cv(data, L, idx_class_origin)
23 if ~exist('idx_class_origin', 'var')
24  idx_class_origin = 0;
25 end;
26 
27 if idx_class_origin == 0
28  % checks if mean-centered; if not, does it
29  flag_ok = 0;
30  try
31  assert_meancentered(data.X);
32  flag_ok = 1;
33  catch ME
34  irverbose(sprintf('Will mean-center the dataset NOW (failed mean-centered test with error message "%s")!', ME.message), 2);
35  end;
36 
37  if ~flag_ok
38  data.X = normaliz(data.X, [], 'c');
39  assert_meancentered(data.X);
40 
41  end;
42 end;
43 
44 
45 if data.nf ~= size(L, 1)
46  irerror(sprintf('Input dataset (nf=%d) incompatible with loadings matrix (nf=%d)', data.nf, size(L, 1)));
47 end;
48 
49 pieces = data_split_classes(data);
50 
51 if idx_class_origin > 0
52  v_shift = -(mean(pieces(idx_class_origin).X, 1)*L)';
53 else
54  v_shift = 0;
55 end;
56 
57 cv = zeros(data.nf, data.nc);
58 for k = 1:data.nc
59  m = (mean(pieces(k).X, 1)*L)';
60  cv(:, k) = L*(m+v_shift); % Linear combination of loadings vectors here
61 end;
function irverbose(in s, in level)
function irerror(in s)
Dataset class.
Definition: irdata.m:30
function assert_meancentered(in X, in tolerance)
function data_split_classes(in data, in hierarchy)
function data_get_cv(in data, in L, in idx_class_origin)
function normaliz(in X, in x, in types, in idxs_fea)