plot_point.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <algorithm>
11 #include <iterator>
14 
15 namespace illumina { namespace interop { namespace logic { namespace plot {
16 
25  template<typename I>
26  void plot_candle_stick(model::plot::candle_stick_point& point, I beg, I end, const float x, std::vector<float>& outliers)
27  {
28  const float eps = 1e-7f;
29  const float NaN = std::numeric_limits<float>::quiet_NaN();
30  INTEROP_ASSERT(beg != end);
31  //std::sort(beg, end);
32  std::stable_sort(beg, end);
33  const float p25 = util::percentile_sorted<float>(beg, end, 25);
34  const float p50 = util::percentile_sorted<float>(beg, end, 50);
35  const float p75 = util::percentile_sorted<float>(beg, end, 75);
36 
37  // Really just some arbitrary criteria derived by empirical observation in the 70s.
38  const float tukey_constant = 1.5f;
39  const float iqr = p75-p25;
40  const float lower = p25 - tukey_constant * iqr;
41  const float upper = p75 + tukey_constant * iqr;
42  if(outliers.capacity()>0)
43  {
44  util::outliers_lower(beg, end, lower, std::back_inserter(outliers));
45  util::outliers_upper(beg, end, upper, std::back_inserter(outliers));
46  }
47  const size_t count = static_cast<size_t>(std::distance(beg,end));
48 
49  I upper_it = std::lower_bound(beg, end, upper);// Not less
50  I lower_it = std::lower_bound(beg, end, lower-(eps*lower));
51 
52 
53 
54  const float max_val = (upper_it != beg) ?
55  ((upper_it == end || *upper_it > upper) ? *(upper_it-1) : *upper_it)
56  : // TODO: should be > not >=
57  ((upper_it != end) ? *upper_it : NaN);
58 
59  const float min_val = (lower_it != end) ? *lower_it : NaN;
60  point = model::plot::candle_stick_point(x, p25, p50, p75, min_val, max_val, count, outliers);
61  outliers.clear();
62  }
63 
64 
65 }}}}
66 
Definition: enum_description.h:15
void outliers_upper(I beg, I end, const F bound, O out)
Definition: statistics.h:334
void outliers_lower(I beg, I end, const F bound, O out)
Definition: statistics.h:313
Definition: candle_stick_point.h:19
#define INTEROP_ASSERT(TST)
Definition: assert.h:21
void plot_candle_stick(model::plot::candle_stick_point &point, I beg, I end, const float x, std::vector< float > &outliers)
Definition: plot_point.h:26