IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
adjust_turn2.m
Go to the documentation of this file.
1 %> @ingroup maths
2 %> @file
3 %> @brief Turns loadings vectors
4 %>
5 %> Turns loadings vectors so that they make less than 90 degrees with their corresponding loadings vectors from a reference block.
6 %>
7 %> Works both with @ref fcon_linear blocks and @ref block_cascade_base blocks. In case of block_cascade_base, only acts on the last block
8 %>
9 %> This function makes sense with eigenvectors of some matrix, e.g., loadings from PCA/LDA/PLS
10 %>
11 %> Acts on the columns of L separately.
12 %>
13 %> as_crossc
14 %
15 %
16 %> @param b Block to act on. Block must have the @c L property
17 %> @param bref Reference block
18 %> @return a [nf]x[nf] "turning" matrix/ This matrix is diagonal with elements either +1 or -1. <code>L*M</code> turns the loadings vector
19 function M = adjust_turn2(b, bref)
20 
21 % flag_cascade = isa(b, 'block_cascade_base');
22 %
23 % if flag_cascade
24 % L = b.blocks{end}.L;
25 % Lref = bref.blocks{end}.L;
26 % else
27  L = b.L;
28  Lref = bref.L;
29 % end;
30 
31 if size(L, 2) ~= size(Lref, 2)
32  irerror(sprintf('Number of loadings do not match: %d against %d', size(L, 2), size(Lref, r)));
33 end;
34 
35 
36 % figure;subplot(2, 1, 1); plot(L(:, 1)); title('L');subplot(2, 1, 2); plot(Lref(:, 1)); title('Lref');
37 % dbstack;
38 % keyboard;
39 % close;
40 
41 flag_any = 0;
42 M = eye(size(L, 2));
43 for i = 1:size(L, 2)
44  Li = L(:, i);
45  if Li'*Lref(:, i) < 0
46  M(i, i) = -1;
47  L(:, i) = -Li;
48  flag_any = 1;
49  end;
50 end;
51 
52 if ~flag_any
53  M = [];
54 end;
Feature Construction - Linear Transformations base class.
Definition: fcon_linear.m:2
function irerror(in s)
Base Block class.
Definition: block.m:2
Cross-calculation Analysis Session.
Definition: as_crossc.m:19
function adjust_turn2(in b, in bref)
Cascade block: sequence of blocks represented by a block.