IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
biocomparer.m
Go to the documentation of this file.
1 %> Biomarkers comparer class
2 %>
3 %> <h3>References</h3>
4 %> Trevisan et al 2012. Submitted to AC.
5 %>
6 %> @sa sigfun.m
7 classdef biocomparer < irobj
8  properties
9  %> =20. "half-height" distance between biomarkers. This is the distance in x-values (wavenumbers) where the degree of agreement
10  %> will be considered to be 50%
11  halfheight = 20;
12  %> =1. Whether to use the weights that are passed to go()
13  flag_use_weights = 1;
14  end;
15 
16  methods
17  %> @param A First set of wavenumbers
18  %> @param B Second set of wavenumbers
19  %> @param WA (Optional) Weights of first set of wavenumbers. If not supplied or supplied as "[]", all weights will be considered the same. The weight scale is irrelevant.
20  %> @param WB (Optional) Weights of second set of wavenumbers. If not supplied or supplied as "[]", all weights will be considered the same. The weight scale is irrelevant.
21  %> @return [matches, finalindex] the "matches" structure has the following fields:
22  %> @arg @c .indexes 2-element vector containing the indexes of the originals
23  %> @arg @c .wns 2-element vector containing the x-positions (wavenumbers/"wns") of the corresponding indexes
24  %> @arg @c .agreement Result of the agreement calculation using the sigmoit function
25  %> @arg @c .weight Average between the (normalized) weights of the matched positions
26  %> @arg @c .strength Just the result of <code>agreement*weight</code>
27  %> The "agreement" will be calculated by a logistic sigmoid function (that of shape 1/(1+exp(x)))
28  function [matches, finalindex] = go(o, A, B, WA, WB)
29 
30  % Parameters check and adjustments
31  if nargin < 4 || isempty(WA) || ~o.flag_use_weights
32  WA = ones(1, numel(A));
33  end;
34  if nargin < 5 || isempty(WB) || ~o.flag_use_weights
35  WB = ones(1, numel(B));
36  end;
37 
38  hh = o.halfheight;
39 
40  [m1, fi1] = o.internal_compare_biomarkers(A, B, WA, WB, hh);
41  [m2, fi2] = o.internal_compare_biomarkers(B, A, WB, WA, hh);
42 
43  % Reverts the indexes and wns of second matches
44  for i = 1:numel(m2)
45  m2(i).indexes = m2(i).indexes([2, 1]);
46  m2(i).wns = m2(i).wns([2, 1]);
47  end;
48 
49 
50  matches = [m1, m2];
51  finalindex = mean([fi1, fi2]);
52  end;
53  end;
54 
55  methods(Access=protected, Static)
56  function [matches, finalindex] = internal_compare_biomarkers(A, B, WA, WB, hh)
57 
58  % Determines some sizes
59  nA = length(A);
60  nB = length(B);
61  nmin = min([nA, nB]);
62  nmax = max([nA, nB]);
63 
64 % sigfun0 = sigfun(0); % Small correction factor, because sigfun(0) = .9975 instead of 1
65 
66  for i = 1:nA
67  % Finds element of B the closest to i-th element in A
68  [val, idx0] = min(abs(A(i)-B));
69 
70  b.indexes = [i, idx0];
71  b.wns = [A(i), B(idx0)];
72  b.agreement = sigfun(val, hh); %/sigfun0;
73  b.weight = mean([WA(i), WB(idx0)]);
74  % b.weight = sqrt(WA(i)*WB(idx0)); % Now geometric mean
75  b.strength = b.agreement*b.weight;
76 
77  matches(i) = b; %#ok<AGROW>
78  end;
79 
80  % Note that if n < nmax, some biomarkers will remain unmatched and the maximum final index will be n/nmax
81 
82  finalindex = sum([matches.strength])/sum([matches.weight]); % Normalizes to 1
83 % finalindex = finalindex; *nA/nmax;
84  end;
85  end;
86 
87  methods
88  function o = biocomparer()
89  o.classtitle = 'Biomarkers comparer';
90  end;
91  end;
92 end
Analysis Session (AS) base class.
Definition: as.m:6
function sigfun(in x, in hh, in flag_demo)
Base class.
Definition: irobj.m:33