IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
blmisc_rowsout_distr.m
Go to the documentation of this file.
1 %> @brief Distribution-Based Outlier Removal
2 %>
3 %> @sa uip_blmisc_rowsout_distr.m
5  properties
6  %> =0.01. Value to be used if type is \c 'threshold'. This is a
7  %> fraction of the maximum value in the histogram
8  threshold = 0.01;
9  %> =0. Range filter: 0-none; 1-left quantile; 2-right quantile
10  quantile = 0;
11  %> =0. Activates "tail trimming mode". In this mode, tails are trimmed starting at the first bin below the
12  %> threshold. This can happen either/both at the first or/and second quantile, depending on the value of the @c
13  %> quantile property.
14  flag_trim_tail = 0;
15  end;
16 
17  methods
18  function o = blmisc_rowsout_distr(o)
19  o.classtitle = 'Distribution Estimation';
20  end;
21 
22  function o = draw_histogram(o)
23  draw_histogram@blmisc_rowsout_uni(o);
24  o.draw_thresholds();
25  end;
26 
27  %> @brief Returns a vector that flags whether each bin goes or not.
28  function z = get_distrboolmap(o, x)
29  nb = length(x); % number of bins
30  z = ones(1, nb);
31  v = 1:nb;
32  i1 = 1;
33  i2 = nb;
34  iq = o.get_idx_50plus(x);
35  if o.quantile == 1 % restricts check to quantile
36  i2 = iq-1;
37  elseif o.quantile == 2
38  i1 = iq;
39  end;
40  absthreshold = o.threshold*max(x);
41  for i = i1:i2
42  if x(i) < absthreshold
43  if o.flag_trim_tail
44  if i < iq
45  z(v <= i) = 0;
46  else
47  z(v >= i) = 0;
48  end;
49  else
50  z(i) = 0;
51  end;
52  end;
53  end;
54  end
55  end;
56 
57  methods(Access=protected)
58  function o = draw_thresholds(o)
59  x1 = o.edges(1);
60  x2 = o.edges(end);
61  maxy = max(o.hits)*1.1;
62  if o.quantile == 1 % left quantile
63  x2 = o.edges(o.get_idx_50plus(o.hits));
64  plot([x2, x2], [0, maxy], 'r', 'LineWidth', 2);
65  hold on;
66  elseif o.quantile == 2 % right quantile
67  x1 = o.edges(o.get_idx_50plus(o.hits));
68  plot([x1, x1], [0, maxy], 'r', 'LineWidth', 2);
69  hold on;
70  end;
71  plot([x1, x2], [1, 1]*o.threshold*max(o.hits), 'r', 'LineWidth', 2);
72  hold on;
73  end;
74  end;
75 end
76 
Distribution-Based Outlier Removal.
Univariate Outlier removal.