OpenMS
Loading...
Searching...
No Matches
StatisticFunctions.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Clemens Groepl, Johannes Junker, Mathias Walzer, Chris Bielow $
7// --------------------------------------------------------------------------
8#pragma once
9
10#include <vector>
15
16#include <algorithm>
17#include <cmath>
18#include <iterator>
19#include <numeric>
20
21namespace OpenMS
22{
23
24 namespace Math
25 {
38 {
39 double blended{0.0};
40 double half_raw{0.0};
41 double half_rob{0.0};
42 double upper_fence{std::numeric_limits<double>::infinity()};
43 double tail_fraction{0.0};
44 double weight{0.0};
45 };
46
54 template <typename IteratorType>
55 static void checkIteratorsNotNULL(IteratorType begin, IteratorType end)
56 {
57 if (begin == end)
58 {
59 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
60 }
61 }
62
70 template <typename IteratorType>
71 static void checkIteratorsEqual(IteratorType begin, IteratorType end)
72 {
73 if (begin != end)
74 {
75 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
76 }
77 }
78
86 template <typename IteratorType1, typename IteratorType2>
88 IteratorType1 begin_b, IteratorType1 end_b,
89 IteratorType2 begin_a, IteratorType2 end_a)
90 {
91 if ((begin_b == end_b) ^ (begin_a == end_a))
92 {
93 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
94 }
95 }
96
102 template <typename IteratorType>
103 static double sum(IteratorType begin, IteratorType end)
104 {
105 return std::accumulate(begin, end, 0.0);
106 }
107
115 template <typename IteratorType>
116 static double mean(IteratorType begin, IteratorType end)
117 {
118 checkIteratorsNotNULL(begin, end);
119 return sum(begin, end) / std::distance(begin, end);
120 }
121
133 template <typename IteratorType>
134 static double median(IteratorType begin, IteratorType end,
135 bool sorted = false)
136 {
137 checkIteratorsNotNULL(begin, end);
138 if (!sorted)
139 {
140 std::sort(begin, end);
141 }
142
143 Size size = std::distance(begin, end);
144 if (size % 2 == 0) // even size => average two middle values
145 {
146 IteratorType it1 = begin;
147 std::advance(it1, size / 2 - 1);
148 IteratorType it2 = it1;
149 std::advance(it2, 1);
150 return (*it1 + *it2) / 2.0;
151 }
152 else
153 {
154 IteratorType it = begin;
155 std::advance(it, (size - 1) / 2);
156 return *it;
157 }
158 }
159
160
180 template <typename IteratorType>
181 double MAD(IteratorType begin, IteratorType end, double median_of_numbers)
182 {
183 std::vector<double> diffs;
184 diffs.reserve(std::distance(begin, end));
185 for (IteratorType it = begin; it != end; ++it)
186 {
187 diffs.push_back(fabs(*it - median_of_numbers));
188 }
189 return median(diffs.begin(), diffs.end(), false);
190 }
191
210 template <typename IteratorType>
211 double MeanAbsoluteDeviation(IteratorType begin, IteratorType end, double mean_of_numbers)
212 {
213 double mean_value {0};
214 for (IteratorType it = begin; it != end; ++it)
215 {
216 mean_value += fabs(*it - mean_of_numbers);
217 }
218 return mean_value / std::distance(begin, end);
219 }
220
236 template <typename IteratorType>
237 static double quantile1st(IteratorType begin, IteratorType end,
238 bool sorted = false)
239 {
240 checkIteratorsNotNULL(begin, end);
241
242 if (!sorted)
243 {
244 std::sort(begin, end);
245 }
246
247 Size size = std::distance(begin, end);
248 if (size < 3) // lower half is empty for size 1 or 2: the first quantile is the minimum
249 {
250 return static_cast<double>(*begin);
251 }
252 if (size % 2 == 0)
253 {
254 return median(begin, begin + (size/2)-1, true); //-1 to exclude median values
255 }
256 return median(begin, begin + (size/2), true);
257 }
258
274 template <typename IteratorType>
275 static double quantile3rd(
276 IteratorType begin, IteratorType end, bool sorted = false)
277 {
278 checkIteratorsNotNULL(begin, end);
279 if (!sorted)
280 {
281 std::sort(begin, end);
282 }
283
284 Size size = std::distance(begin, end);
285 if (size < 3) // upper half is empty for size 1 or 2: the third quantile is the maximum
286 {
287 return static_cast<double>(*(begin + (size - 1)));
288 }
289 return median(begin + (size/2)+1, end, true); //+1 to exclude median values
290 }
291
317 template <typename IteratorType>
318 static double quantile(IteratorType begin, IteratorType end, double q)
319 {
320 OPENMS_PRECONDITION(std::is_sorted(begin, end),
321 "Math::quantile expects a sorted range. Sort before calling.");
322
323 checkIteratorsNotNULL(begin, end);
324
325 const Size n = std::distance(begin, end);
326 if (n == 0)
327 {
328 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
329 }
330 if (q < 0.0 || q > 1.0)
331 {
332 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
333 "q must be in [0,1]",StringUtils::toStr(q));
334 }
335 if (n == 1) return static_cast<double>(*begin);
336
337 const double pos = q * static_cast<double>(n - 1);
338 const Size i = static_cast<Size>(std::floor(pos));
339 const double frac = pos - static_cast<double>(i);
340
341 const auto it_i = begin + static_cast<typename std::iterator_traits<IteratorType>::difference_type>(i);
342 if (frac == 0.0) return static_cast<double>(*it_i);
343
344 const auto it_ip1 = it_i + 1;
345 return (1.0 - frac) * static_cast<double>(*it_i) + frac * static_cast<double>(*it_ip1);
346 }
347
362 template <typename IteratorType>
363 double tukeyUpperFence(IteratorType begin, IteratorType end, double k = 1.5)
364 {
365 std::vector<double> v;
366 v.reserve(std::distance(begin, end));
367 for (auto it = begin; it != end; ++it)
368 {
369 if (std::isfinite(*it)) v.push_back(static_cast<double>(*it));
370 }
371 if (v.size() < 4) return std::numeric_limits<double>::infinity();
372
373 std::sort(v.begin(), v.end());
374 const double q1 = quantile(v.begin(), v.end(), 0.25);
375 const double q3 = quantile(v.begin(), v.end(), 0.75);
376 const double iqr = q3 - q1;
377 if (!(iqr > 0.0)) return std::numeric_limits<double>::infinity();
378
379 return q3 + k * iqr;
380 }
381
391 template <typename IteratorType>
392 double tailFractionAbove(IteratorType begin, IteratorType end, double threshold)
393 {
394 size_t n = 0, n_tail = 0;
395 for (auto it = begin; it != end; ++it)
396 {
397 const double x = static_cast<double>(*it);
398 if (!std::isfinite(x)) continue;
399 ++n;
400 if (x > threshold) ++n_tail;
401 }
402 return (n == 0) ? 0.0 : static_cast<double>(n_tail) / static_cast<double>(n);
403 }
404
423 template <typename IteratorType>
424 double winsorizedQuantile(IteratorType begin, IteratorType end, double q, double upper_fence)
425 {
426 std::vector<double> v;
427 v.reserve(std::distance(begin, end));
428 for (auto it = begin; it != end; ++it)
429 {
430 const double x = static_cast<double>(*it);
431 if (!std::isfinite(x)) continue;
432 v.push_back(x);
433 }
434 if (v.empty()) return 0.0;
435
436 if (std::isfinite(upper_fence))
437 {
438 for (double& x : v)
439 {
440 if (x > upper_fence) x = upper_fence;
441 if (x < 0.0) x = 0.0; // defensive; useful when passing |residual|
442 }
443 }
444 std::sort(v.begin(), v.end());
445 return quantile(v.begin(), v.end(), q);
446 }
447
482 template <typename IteratorType>
483 AdaptiveQuantileResult adaptiveQuantile(IteratorType begin, IteratorType end, double q,
484 double k = 1.5,
485 double r_sparse = 0.01,
486 double r_dense = 0.10)
487 {
489
490 // Copy finite values
491 std::vector<double> v;
492 v.reserve(std::distance(begin, end));
493 for (auto it = begin; it != end; ++it)
494 {
495 if (std::isfinite(*it)) v.push_back(static_cast<double>(*it));
496 }
497 if (v.empty())
498 {
499 return res;
500 }
501
502 std::sort(v.begin(), v.end());
503 const double half_raw = quantile(v.begin(), v.end(), q);
504
505 // Robust path (winsorization at Tukey fence)
506 const double uf = tukeyUpperFence(v.begin(), v.end(), k);
507 const double r = std::isfinite(uf) ? tailFractionAbove(v.begin(), v.end(), uf) : 0.0;
508 const double half_rob = winsorizedQuantile(v.begin(), v.end(), q, uf);
509
510 // Blend weight w(r)
511 double w = 0.0;
512 if (r_dense <= r_sparse)
513 {
514 w = (r > r_sparse) ? 1.0 : 0.0;
515 }
516 else
517 {
518 const double t = (r - r_sparse) / (r_dense - r_sparse);
519 w = std::max(0.0, std::min(1.0, t));
520 }
521
522 res.half_raw = half_raw;
523 res.half_rob = half_rob;
524 res.upper_fence = uf;
525 res.tail_fraction = r;
526 res.weight = w;
527 res.blended = (1.0 - w) * half_rob + w * half_raw;
528 return res;
529 }
530
540 template <typename IteratorType>
541 static double variance(IteratorType begin, IteratorType end,
542 double mean = std::numeric_limits<double>::max())
543 {
544 checkIteratorsNotNULL(begin, end);
545 double sum_value = 0.0;
546 if (mean == std::numeric_limits<double>::max())
547 {
548 mean = Math::mean(begin, end);
549 }
550 for (IteratorType iter=begin; iter!=end; ++iter)
551 {
552 double diff = *iter - mean;
553 sum_value += diff * diff;
554 }
555 return sum_value / (std::distance(begin, end)-1);
556 }
557
567 template <typename IteratorType>
568 static double sd(IteratorType begin, IteratorType end,
569 double mean = std::numeric_limits<double>::max())
570 {
571 checkIteratorsNotNULL(begin, end);
572 return std::sqrt( variance(begin, end, mean) );
573 }
574
582 template <typename IteratorType>
583 static double absdev(IteratorType begin, IteratorType end,
584 double mean = std::numeric_limits<double>::max())
585 {
586 checkIteratorsNotNULL(begin, end);
587 if (mean == std::numeric_limits<double>::max())
588 {
589 mean = Math::mean(begin, end);
590 }
591 return MeanAbsoluteDeviation(begin, end, mean);
592 }
593
603 template <typename IteratorType1, typename IteratorType2>
604 static double covariance(IteratorType1 begin_a, IteratorType1 end_a,
605 IteratorType2 begin_b, IteratorType2 end_b)
606 {
607 //no data or different lengths
608 checkIteratorsNotNULL(begin_a, end_a);
609
610 double sum_value = 0.0;
611 double mean_a = Math::mean(begin_a, end_a);
612 double mean_b = Math::mean(begin_b, end_b);
613 IteratorType1 iter_a = begin_a;
614 IteratorType2 iter_b = begin_b;
615 for (; iter_a != end_a; ++iter_a, ++iter_b)
616 {
617 /* assure both ranges have the same number of elements */
618 checkIteratorsAreValid(begin_b, end_b, begin_a, end_a);
619 sum_value += (*iter_a - mean_a) * (*iter_b - mean_b);
620 }
621 /* assure both ranges have the same number of elements */
622 checkIteratorsEqual(iter_b, end_b);
623 Size n = std::distance(begin_a, end_a);
624 return sum_value / (n-1);
625 }
626
636 template <typename IteratorType1, typename IteratorType2>
637 static double meanSquareError(IteratorType1 begin_a, IteratorType1 end_a,
638 IteratorType2 begin_b, IteratorType2 end_b)
639 {
640 //no data or different lengths
641 checkIteratorsNotNULL(begin_a, end_a);
642
643 SignedSize dist = std::distance(begin_a, end_a);
644 double error = 0;
645 IteratorType1 iter_a = begin_a;
646 IteratorType2 iter_b = begin_b;
647 for (; iter_a != end_a; ++iter_a, ++iter_b)
648 {
649 /* assure both ranges have the same number of elements */
650 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
651
652 double tmp(*iter_a - *iter_b);
653 error += tmp * tmp;
654 }
655 /* assure both ranges have the same number of elements */
656 checkIteratorsEqual(iter_b, end_b);
657
658 return error / dist;
659 }
660
673 template <typename IteratorType1, typename IteratorType2>
674 static double rootMeanSquareError(IteratorType1 begin_a, IteratorType1 end_a,
675 IteratorType2 begin_b, IteratorType2 end_b)
676 {
677 return std::sqrt(meanSquareError(begin_a, end_a, begin_b, end_b));
678 }
679
689 template <typename IteratorType1, typename IteratorType2>
690 static double classificationRate(IteratorType1 begin_a, IteratorType1 end_a,
691 IteratorType2 begin_b, IteratorType2 end_b)
692 {
693 //no data or different lengths
694 checkIteratorsNotNULL(begin_a, end_a);
695
696 SignedSize dist = std::distance(begin_a, end_a);
697 SignedSize correct = dist;
698 IteratorType1 iter_a = begin_a;
699 IteratorType2 iter_b = begin_b;
700 for (; iter_a != end_a; ++iter_a, ++iter_b)
701 {
702 /* assure both ranges have the same number of elements */
703 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
704 if ((*iter_a < 0 && *iter_b >= 0) || (*iter_a >= 0 && *iter_b < 0))
705 {
706 --correct;
707 }
708
709 }
710 /* assure both ranges have the same number of elements */
711 checkIteratorsEqual(iter_b, end_b);
712
713 return double(correct) / dist;
714 }
715
728 template <typename IteratorType1, typename IteratorType2>
730 IteratorType1 begin_a, IteratorType1 end_a,
731 IteratorType2 begin_b, IteratorType2 end_b)
732 {
733 //no data or different lengths
734 checkIteratorsNotNULL(begin_a, end_b);
735
736 double tp = 0;
737 double fp = 0;
738 double tn = 0;
739 double fn = 0;
740 IteratorType1 iter_a = begin_a;
741 IteratorType2 iter_b = begin_b;
742 for (; iter_a != end_a; ++iter_a, ++iter_b)
743 {
744 /* assure both ranges have the same number of elements */
745 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
746
747 if (*iter_a < 0 && *iter_b >= 0)
748 {
749 ++fn;
750 }
751 else if (*iter_a < 0 && *iter_b < 0)
752 {
753 ++tn;
754 }
755 else if (*iter_a >= 0 && *iter_b >= 0)
756 {
757 ++tp;
758 }
759 else if (*iter_a >= 0 && *iter_b < 0)
760 {
761 ++fp;
762 }
763 }
764 /* assure both ranges have the same number of elements */
765 checkIteratorsEqual(iter_b, end_b);
766
767 return (tp * tn - fp * fn) / std::sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn));
768 }
769
781 template <typename IteratorType1, typename IteratorType2>
783 IteratorType1 begin_a, IteratorType1 end_a,
784 IteratorType2 begin_b, IteratorType2 end_b)
785 {
786 //no data or different lengths
787 checkIteratorsNotNULL(begin_a, end_a);
788
789 //calculate average
790 SignedSize dist = std::distance(begin_a, end_a);
791 double avg_a = std::accumulate(begin_a, end_a, 0.0) / dist;
792 double avg_b = std::accumulate(begin_b, end_b, 0.0) / dist;
793
794 double numerator = 0;
795 double denominator_a = 0;
796 double denominator_b = 0;
797 IteratorType1 iter_a = begin_a;
798 IteratorType2 iter_b = begin_b;
799 for (; iter_a != end_a; ++iter_a, ++iter_b)
800 {
801 /* assure both ranges have the same number of elements */
802 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
803 double temp_a = *iter_a - avg_a;
804 double temp_b = *iter_b - avg_b;
805 numerator += (temp_a * temp_b);
806 denominator_a += (temp_a * temp_a);
807 denominator_b += (temp_b * temp_b);
808 }
809 /* assure both ranges have the same number of elements */
810 checkIteratorsEqual(iter_b, end_b);
811 return numerator / std::sqrt(denominator_a * denominator_b);
812 }
813
815 template <typename Value>
816 static void computeRank(std::vector<Value> & w)
817 {
818 Size i = 0; // main index
819 Size z = 0; // "secondary" index
820 Value rank = 0;
821 Size n = (w.size() - 1);
822 //store original indices for later
823 std::vector<std::pair<Size, Value> > w_idx;
824 for (Size j = 0; j < w.size(); ++j)
825 {
826 w_idx.push_back(std::make_pair(j, w[j]));
827 }
828 //sort
829 std::sort(w_idx.begin(), w_idx.end(),
830 [](const auto& pair1, const auto& pair2) { return pair1.second < pair2.second; });
831 //replace pairs <orig_index, value> in w_idx by pairs <orig_index, rank>
832 while (i < n)
833 {
834 // test for equality with tolerance:
835 if (fabs(w_idx[i + 1].second - w_idx[i].second) > 0.0000001 * fabs(w_idx[i + 1].second)) // no tie
836 {
837 w_idx[i].second = Value(i + 1);
838 ++i;
839 }
840 else // tie, replace by mean rank
841 {
842 // count number of ties
843 for (z = i + 1; (z <= n) && fabs(w_idx[z].second - w_idx[i].second) <= 0.0000001 * fabs(w_idx[z].second); ++z)
844 {
845 }
846 // compute mean rank of tie
847 rank = 0.5 * (i + z + 1);
848 // replace intensities by rank
849 for (Size v = i; v <= z - 1; ++v)
850 {
851 w_idx[v].second = rank;
852 }
853 i = z;
854 }
855 }
856 if (i == n)
857 w_idx[n].second = Value(n + 1);
858 //restore original order and replace elements of w with their ranks
859 for (Size j = 0; j < w.size(); ++j)
860 {
861 w[w_idx[j].first] = w_idx[j].second;
862 }
863 }
864
876 template <typename IteratorType1, typename IteratorType2>
878 IteratorType1 begin_a, IteratorType1 end_a,
879 IteratorType2 begin_b, IteratorType2 end_b)
880 {
881 //no data or different lengths
882 checkIteratorsNotNULL(begin_a, end_a);
883
884 // store and sort intensities of model and data
885 SignedSize dist = std::distance(begin_a, end_a);
886 std::vector<double> ranks_data;
887 ranks_data.reserve(dist);
888 std::vector<double> ranks_model;
889 ranks_model.reserve(dist);
890 IteratorType1 iter_a = begin_a;
891 IteratorType2 iter_b = begin_b;
892 for (; iter_a != end_a; ++iter_a, ++iter_b)
893 {
894 /* assure both ranges have the same number of elements */
895 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
896
897 ranks_model.push_back(*iter_a);
898 ranks_data.push_back(*iter_b);
899 }
900 /* assure both ranges have the same number of elements */
901 checkIteratorsEqual(iter_b, end_b);
902
903 // replace entries by their ranks
904 computeRank(ranks_data);
905 computeRank(ranks_model);
906
907 double mu = double(ranks_data.size() + 1) / 2.; // mean of ranks
908 // Was the following, but I think the above is more correct ... (Clemens)
909 // double mu = (ranks_data.size() + 1) / 2;
910
911 double sum_model_data = 0;
912 double sqsum_data = 0;
913 double sqsum_model = 0;
914
915 for (Int i = 0; i < dist; ++i)
916 {
917 sum_model_data += (ranks_data[i] - mu) * (ranks_model[i] - mu);
918 sqsum_data += (ranks_data[i] - mu) * (ranks_data[i] - mu);
919 sqsum_model += (ranks_model[i] - mu) * (ranks_model[i] - mu);
920 }
921
922 // check for division by zero
923 if (!sqsum_data || !sqsum_model)
924 {
925 return 0;
926 }
927
928 return sum_model_data / (std::sqrt(sqsum_data) * std::sqrt(sqsum_model));
929 }
930
932 template<typename T>
934 {
935 SummaryStatistics() = default;
936
937 // Ctor with data
939 {
940 count = data.size();
941 // Sanity check: avoid core dump if no data points present.
942 if (data.empty())
943 {
944 mean = variance = min = lowerq = median = upperq = max = 0.0;
945 }
946 else
947 {
948 sort(data.begin(), data.end());
949 mean = Math::mean(data.begin(), data.end());
950 // variance divides by (n-1) and is undefined for a single value; report 0.0 as in the empty case
951 variance = (count > 1) ? Math::variance(data.begin(), data.end(), mean) : 0.0;
952 min = data.front();
953 lowerq = Math::quantile1st(data.begin(), data.end(), true);
954 median = Math::median(data.begin(), data.end(), true);
955 upperq = Math::quantile3rd(data.begin(), data.end(), true);
956 max = data.back();
957 }
958 }
959
960 double mean = 0, variance = 0 , lowerq = 0, median = 0, upperq = 0;
961 typename T::value_type min = 0, max = 0;
962 size_t count = 0;
963 };
964
965 } // namespace Math
966} // namespace OpenMS
967
Invalid range exception.
Definition Exception.h:257
Invalid value exception.
Definition Exception.h:306
int Int
Signed integer type.
Definition Types.h:72
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition Types.h:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition openms/include/OpenMS/CONCEPT/Macros.h:91
static double pearsonCorrelationCoefficient(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
Calculates the Pearson correlation coefficient for the values in [begin_a, end_a) and [begin_b,...
Definition StatisticFunctions.h:782
double MAD(IteratorType begin, IteratorType end, double median_of_numbers)
median absolute deviation (MAD)
Definition StatisticFunctions.h:181
static void checkIteratorsAreValid(IteratorType1 begin_b, IteratorType1 end_b, IteratorType2 begin_a, IteratorType2 end_a)
Helper function checking if an iterator and a co-iterator both have a next element.
Definition StatisticFunctions.h:87
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition StatisticFunctions.h:116
static double matthewsCorrelationCoefficient(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
Calculates the Matthews correlation coefficient for the values in [begin_a, end_a) and [begin_b,...
Definition StatisticFunctions.h:729
static void checkIteratorsEqual(IteratorType begin, IteratorType end)
Helper function checking if two iterators are equal.
Definition StatisticFunctions.h:71
static double classificationRate(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
Calculates the classification rate for the values in [begin_a, end_a) and [begin_b,...
Definition StatisticFunctions.h:690
static double rankCorrelationCoefficient(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
calculates the rank correlation coefficient for the values in [begin_a, end_a) and [begin_b,...
Definition StatisticFunctions.h:877
static double quantile3rd(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the third quantile of a range of values.
Definition StatisticFunctions.h:275
static double covariance(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
Calculates the covariance of two ranges of values.
Definition StatisticFunctions.h:604
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition StatisticFunctions.h:103
static void checkIteratorsNotNULL(IteratorType begin, IteratorType end)
Helper function checking if two iterators are not equal.
Definition StatisticFunctions.h:55
static double median(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the median of a range of values.
Definition StatisticFunctions.h:134
static double quantile1st(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the first quantile of a range of values.
Definition StatisticFunctions.h:237
static double meanSquareError(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
Calculates the mean square error for the values in [begin_a, end_a) and [begin_b, end_b)
Definition StatisticFunctions.h:637
static double rootMeanSquareError(IteratorType1 begin_a, IteratorType1 end_a, IteratorType2 begin_b, IteratorType2 end_b)
Calculates the root mean square error (RMSE) for the values in [begin_a, end_a) and [begin_b,...
Definition StatisticFunctions.h:674
double MeanAbsoluteDeviation(IteratorType begin, IteratorType end, double mean_of_numbers)
mean absolute deviation (MeanAbsoluteDeviation)
Definition StatisticFunctions.h:211
static double sd(IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
Calculates the standard deviation of a range of values.
Definition StatisticFunctions.h:568
static double absdev(IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
Calculates the absolute deviation of a range of values.
Definition StatisticFunctions.h:583
double tailFractionAbove(IteratorType begin, IteratorType end, double threshold)
Fraction of values above a threshold.
Definition StatisticFunctions.h:392
double half_raw
Definition StatisticFunctions.h:40
double tail_fraction
Definition StatisticFunctions.h:43
double blended
Definition StatisticFunctions.h:39
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:460
double upper_fence
Definition StatisticFunctions.h:42
double tukeyUpperFence(IteratorType begin, IteratorType end, double k=1.5)
Tukey upper fence (UF) for outlier detection.
Definition StatisticFunctions.h:363
double weight
Definition StatisticFunctions.h:44
static void computeRank(std::vector< Value > &w)
Replaces the elements in vector w by their ranks.
Definition StatisticFunctions.h:816
double winsorizedQuantile(IteratorType begin, IteratorType end, double q, double upper_fence)
Quantile after winsorizing at an upper fence.
Definition StatisticFunctions.h:424
static double variance(IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
Definition StatisticFunctions.h:541
double half_rob
Definition StatisticFunctions.h:41
AdaptiveQuantileResult adaptiveQuantile(IteratorType begin, IteratorType end, double q, double k=1.5, double r_sparse=0.01, double r_dense=0.10)
Adaptive quantile that blends RAW and IQR-winsorized quantiles based on tail density beyond the Tukey...
Definition StatisticFunctions.h:483
Result of adaptiveQuantile computation.
Definition StatisticFunctions.h:38
std::string toStr(int i)
Definition StringUtils.h:101
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Helper class to gather (and dump) some statistics from a e.g. vector<double>.
Definition StatisticFunctions.h:934
double lowerq
Definition StatisticFunctions.h:960
double variance
Definition StatisticFunctions.h:960
T::value_type max
Definition StatisticFunctions.h:961
SummaryStatistics(T &data)
Definition StatisticFunctions.h:938
double median
Definition StatisticFunctions.h:960
size_t count
Definition StatisticFunctions.h:962
double mean
Definition StatisticFunctions.h:960
double upperq
Definition StatisticFunctions.h:960
T::value_type min
Definition StatisticFunctions.h:961