OpenMS  3.0.0
unused.h
Go to the documentation of this file.
1 
2 //#define ANNOTATED_QUANTILES 1
3 #ifdef ANNOTATED_QUANTILES
4 
5 #include <boost/accumulators/statistics/p_square_quantile.hpp>
6 #include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
7 using namespace boost::accumulators;
8 
9 typedef accumulator_set<double, stats<tag::p_square_quantile> > quantile_accu_t;
10 typedef accumulator_set<double, stats<tag::extended_p_square_quantile(quadratic)> > accumulator_t_quadratic;
11 
12 struct SpectrumLevelScoreQuantiles
13 {
14  SpectrumLevelScoreQuantiles():
15  acc_(extended_p_square_probabilities = std::vector<double>{ 0.0, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 0.999, 0.9999, 0.99999, 1.00 })
16  {
17  }
18  void insert(double v) { acc_(v); }
19 
20  double quantileOfValue(double v)
21  {
22  double l = 0.0;
23  double h = 1.0;
24  double mid = l + (h - l) / 2.0; // we start with the median (0.5)
25  double p_value = quantile(acc_, quantile_probability = mid); // value of quantile p
26 
27  size_t iter(0);
28  while (fabs(p_value - v) > 0.01 && iter < 100)
29  {
30  mid = l + (h - l) / 2.0;
31  p_value = quantile(acc_, quantile_probability = mid); // value of quantile p (e.g., 1234.56)
32  if (p_value > v) // if the current quantile value (e.g., of the median) has a value larger than our value of interest
33  {
34  h = mid; // then we need to search in the lower quantile range
35  }
36  else
37  {
38  l = mid;
39  }
40  ++iter;
41  }
42  return l;
43  }
44  private:
45  accumulator_t_quadratic acc_;
46 };
47 
48 #endif
49 
50 
STL namespace.
T1::value_type quantile(const T1 &x, double q)
Returns the value of the q th quantile (0-1) in a sorted non-empty vector x.
Definition: MathFunctions.h:389
const double h
Definition: Constants.h:167