IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
find_distributionthreshold.m
Go to the documentation of this file.
1 %> @ingroup maths
2 %> @file
3 %> @brief Originally created for Nik's study [1]
4 %>
5 %> [1] Purandare, N. C., Patel, I. I., Trevisan, J., Bolger, N., Kelehan, R., von Bünau, G., ... & Martin, F. L. (2013).
6 %> Biospectroscopy insights into the multi-stage process of cervical cancer development: probing for spectral biomarkers
7 %> in cytology to distinguish grades. Analyst.
8 %
9 %> @param ds a two-class, 1-feature dataset
10 %> @return threshold
11 function threshold = find_distributionthreshold(ds)
12 
13 NP = 400;
14 
15 pieces = data_split_classes(ds);
16 
17 % If first class has greater mean, swaps
18 if mean(pieces(1).X(:, 1)) > mean(pieces(2).X(:, 1))
19  pieces = pieces([2, 1]);
20 end;
21 
22 X1 = pieces(1).X(:, 1)';
23 X2 = pieces(2).X(:, 1)';
24 
25 % "class probabilities"
26 p1 = pieces(1).no;
27 p2 = pieces(2).no;
28 
29 xmin = min([X1 X2]);
30 xmax = max([X1 X2]);
31 
32 
33 
34 xinter = linspace(xmin, xmax, NP);
35 
36 [x1, y1] = distribution(pieces(1).X, NP, [xmin, xmax]);
37 [x2, y2] = distribution(pieces(2).X, NP, [xmin, xmax]);
38 
39 yinter1 = spline(x1, y1, xinter)*p1;
40 yinter2 = spline(x2, y2, xinter)*p2;
41 
42 if 1
43  figure;
44  plot(xinter, yinter1);
45  hold on;
46  plot(xinter, yinter2, 'k');
47  disp('hello from find_distribution threshold');
48 end;
49 
50 % Finds top of first mountain to start from there
51 [top1_value, top1_index] = max(yinter1);
52 
53 threshold = [];
54 for i = top1_index:NP
55  if yinter1(i) < yinter2(i)
56  if i == top1_index
57 % irerror('Mountain with lowest average is completely engulfed!');
58  irwarning('Mountain with lowest average is completely engulfed!');
59  threshold = (xmax+xmin)/2;
60  break;
61  else
62  % Done!
63  threshold = xinter(i-1);
64  break;
65  end;
66  end;
67 end;
68 if isempty(threshold)
69 % irerror('Mountain with highest average is completely engulfed!');
70  irwarning('Mountain with highest average is completely engulfed!');
71  threshold = (xmax+xmin)/2;
72 end;