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
234 template <typename IteratorType>
235 static double quantile1st(IteratorType begin, IteratorType end,
236 bool sorted = false)
237 {
238 checkIteratorsNotNULL(begin, end);
239
240 if (!sorted)
241 {
242 std::sort(begin, end);
243 }
244
245 Size size = std::distance(begin, end);
246 if (size % 2 == 0)
247 {
248 return median(begin, begin + (size/2)-1, true); //-1 to exclude median values
249 }
250 return median(begin, begin + (size/2), true);
251 }
252
266 template <typename IteratorType>
267 static double quantile3rd(
268 IteratorType begin, IteratorType end, bool sorted = false)
269 {
270 checkIteratorsNotNULL(begin, end);
271 if (!sorted)
272 {
273 std::sort(begin, end);
274 }
275
276 Size size = std::distance(begin, end);
277 return median(begin + (size/2)+1, end, true); //+1 to exclude median values
278 }
279
305 template <typename IteratorType>
306 static double quantile(IteratorType begin, IteratorType end, double q)
307 {
308 OPENMS_PRECONDITION(std::is_sorted(begin, end),
309 "Math::quantile expects a sorted range. Sort before calling.");
310
311 checkIteratorsNotNULL(begin, end);
312
313 const Size n = std::distance(begin, end);
314 if (n == 0)
315 {
316 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
317 }
318 if (q < 0.0 || q > 1.0)
319 {
320 throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
321 "q must be in [0,1]",StringUtils::toStr(q));
322 }
323 if (n == 1) return static_cast<double>(*begin);
324
325 const double pos = q * static_cast<double>(n - 1);
326 const Size i = static_cast<Size>(std::floor(pos));
327 const double frac = pos - static_cast<double>(i);
328
329 const auto it_i = begin + static_cast<typename std::iterator_traits<IteratorType>::difference_type>(i);
330 if (frac == 0.0) return static_cast<double>(*it_i);
331
332 const auto it_ip1 = it_i + 1;
333 return (1.0 - frac) * static_cast<double>(*it_i) + frac * static_cast<double>(*it_ip1);
334 }
335
350 template <typename IteratorType>
351 double tukeyUpperFence(IteratorType begin, IteratorType end, double k = 1.5)
352 {
353 std::vector<double> v;
354 v.reserve(std::distance(begin, end));
355 for (auto it = begin; it != end; ++it)
356 {
357 if (std::isfinite(*it)) v.push_back(static_cast<double>(*it));
358 }
359 if (v.size() < 4) return std::numeric_limits<double>::infinity();
360
361 std::sort(v.begin(), v.end());
362 const double q1 = quantile(v.begin(), v.end(), 0.25);
363 const double q3 = quantile(v.begin(), v.end(), 0.75);
364 const double iqr = q3 - q1;
365 if (!(iqr > 0.0)) return std::numeric_limits<double>::infinity();
366
367 return q3 + k * iqr;
368 }
369
379 template <typename IteratorType>
380 double tailFractionAbove(IteratorType begin, IteratorType end, double threshold)
381 {
382 size_t n = 0, n_tail = 0;
383 for (auto it = begin; it != end; ++it)
384 {
385 const double x = static_cast<double>(*it);
386 if (!std::isfinite(x)) continue;
387 ++n;
388 if (x > threshold) ++n_tail;
389 }
390 return (n == 0) ? 0.0 : static_cast<double>(n_tail) / static_cast<double>(n);
391 }
392
411 template <typename IteratorType>
412 double winsorizedQuantile(IteratorType begin, IteratorType end, double q, double upper_fence)
413 {
414 std::vector<double> v;
415 v.reserve(std::distance(begin, end));
416 for (auto it = begin; it != end; ++it)
417 {
418 const double x = static_cast<double>(*it);
419 if (!std::isfinite(x)) continue;
420 v.push_back(x);
421 }
422 if (v.empty()) return 0.0;
423
424 if (std::isfinite(upper_fence))
425 {
426 for (double& x : v)
427 {
428 if (x > upper_fence) x = upper_fence;
429 if (x < 0.0) x = 0.0; // defensive; useful when passing |residual|
430 }
431 }
432 std::sort(v.begin(), v.end());
433 return quantile(v.begin(), v.end(), q);
434 }
435
470 template <typename IteratorType>
471 AdaptiveQuantileResult adaptiveQuantile(IteratorType begin, IteratorType end, double q,
472 double k = 1.5,
473 double r_sparse = 0.01,
474 double r_dense = 0.10)
475 {
477
478 // Copy finite values
479 std::vector<double> v;
480 v.reserve(std::distance(begin, end));
481 for (auto it = begin; it != end; ++it)
482 {
483 if (std::isfinite(*it)) v.push_back(static_cast<double>(*it));
484 }
485 if (v.empty())
486 {
487 return res;
488 }
489
490 std::sort(v.begin(), v.end());
491 const double half_raw = quantile(v.begin(), v.end(), q);
492
493 // Robust path (winsorization at Tukey fence)
494 const double uf = tukeyUpperFence(v.begin(), v.end(), k);
495 const double r = std::isfinite(uf) ? tailFractionAbove(v.begin(), v.end(), uf) : 0.0;
496 const double half_rob = winsorizedQuantile(v.begin(), v.end(), q, uf);
497
498 // Blend weight w(r)
499 double w = 0.0;
500 if (r_dense <= r_sparse)
501 {
502 w = (r > r_sparse) ? 1.0 : 0.0;
503 }
504 else
505 {
506 const double t = (r - r_sparse) / (r_dense - r_sparse);
507 w = std::max(0.0, std::min(1.0, t));
508 }
509
510 res.half_raw = half_raw;
511 res.half_rob = half_rob;
512 res.upper_fence = uf;
513 res.tail_fraction = r;
514 res.weight = w;
515 res.blended = (1.0 - w) * half_rob + w * half_raw;
516 return res;
517 }
518
528 template <typename IteratorType>
529 static double variance(IteratorType begin, IteratorType end,
530 double mean = std::numeric_limits<double>::max())
531 {
532 checkIteratorsNotNULL(begin, end);
533 double sum_value = 0.0;
534 if (mean == std::numeric_limits<double>::max())
535 {
536 mean = Math::mean(begin, end);
537 }
538 for (IteratorType iter=begin; iter!=end; ++iter)
539 {
540 double diff = *iter - mean;
541 sum_value += diff * diff;
542 }
543 return sum_value / (std::distance(begin, end)-1);
544 }
545
555 template <typename IteratorType>
556 static double sd(IteratorType begin, IteratorType end,
557 double mean = std::numeric_limits<double>::max())
558 {
559 checkIteratorsNotNULL(begin, end);
560 return std::sqrt( variance(begin, end, mean) );
561 }
562
570 template <typename IteratorType>
571 static double absdev(IteratorType begin, IteratorType end,
572 double mean = std::numeric_limits<double>::max())
573 {
574 checkIteratorsNotNULL(begin, end);
575 if (mean == std::numeric_limits<double>::max())
576 {
577 mean = Math::mean(begin, end);
578 }
579 return MeanAbsoluteDeviation(begin, end, mean);
580 }
581
591 template <typename IteratorType1, typename IteratorType2>
592 static double covariance(IteratorType1 begin_a, IteratorType1 end_a,
593 IteratorType2 begin_b, IteratorType2 end_b)
594 {
595 //no data or different lengths
596 checkIteratorsNotNULL(begin_a, end_a);
597
598 double sum_value = 0.0;
599 double mean_a = Math::mean(begin_a, end_a);
600 double mean_b = Math::mean(begin_b, end_b);
601 IteratorType1 iter_a = begin_a;
602 IteratorType2 iter_b = begin_b;
603 for (; iter_a != end_a; ++iter_a, ++iter_b)
604 {
605 /* assure both ranges have the same number of elements */
606 checkIteratorsAreValid(begin_b, end_b, begin_a, end_a);
607 sum_value += (*iter_a - mean_a) * (*iter_b - mean_b);
608 }
609 /* assure both ranges have the same number of elements */
610 checkIteratorsEqual(iter_b, end_b);
611 Size n = std::distance(begin_a, end_a);
612 return sum_value / (n-1);
613 }
614
624 template <typename IteratorType1, typename IteratorType2>
625 static double meanSquareError(IteratorType1 begin_a, IteratorType1 end_a,
626 IteratorType2 begin_b, IteratorType2 end_b)
627 {
628 //no data or different lengths
629 checkIteratorsNotNULL(begin_a, end_a);
630
631 SignedSize dist = std::distance(begin_a, end_a);
632 double error = 0;
633 IteratorType1 iter_a = begin_a;
634 IteratorType2 iter_b = begin_b;
635 for (; iter_a != end_a; ++iter_a, ++iter_b)
636 {
637 /* assure both ranges have the same number of elements */
638 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
639
640 double tmp(*iter_a - *iter_b);
641 error += tmp * tmp;
642 }
643 /* assure both ranges have the same number of elements */
644 checkIteratorsEqual(iter_b, end_b);
645
646 return error / dist;
647 }
648
661 template <typename IteratorType1, typename IteratorType2>
662 static double rootMeanSquareError(IteratorType1 begin_a, IteratorType1 end_a,
663 IteratorType2 begin_b, IteratorType2 end_b)
664 {
665 return std::sqrt(meanSquareError(begin_a, end_a, begin_b, end_b));
666 }
667
677 template <typename IteratorType1, typename IteratorType2>
678 static double classificationRate(IteratorType1 begin_a, IteratorType1 end_a,
679 IteratorType2 begin_b, IteratorType2 end_b)
680 {
681 //no data or different lengths
682 checkIteratorsNotNULL(begin_a, end_a);
683
684 SignedSize dist = std::distance(begin_a, end_a);
685 SignedSize correct = dist;
686 IteratorType1 iter_a = begin_a;
687 IteratorType2 iter_b = begin_b;
688 for (; iter_a != end_a; ++iter_a, ++iter_b)
689 {
690 /* assure both ranges have the same number of elements */
691 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
692 if ((*iter_a < 0 && *iter_b >= 0) || (*iter_a >= 0 && *iter_b < 0))
693 {
694 --correct;
695 }
696
697 }
698 /* assure both ranges have the same number of elements */
699 checkIteratorsEqual(iter_b, end_b);
700
701 return double(correct) / dist;
702 }
703
716 template <typename IteratorType1, typename IteratorType2>
718 IteratorType1 begin_a, IteratorType1 end_a,
719 IteratorType2 begin_b, IteratorType2 end_b)
720 {
721 //no data or different lengths
722 checkIteratorsNotNULL(begin_a, end_b);
723
724 double tp = 0;
725 double fp = 0;
726 double tn = 0;
727 double fn = 0;
728 IteratorType1 iter_a = begin_a;
729 IteratorType2 iter_b = begin_b;
730 for (; iter_a != end_a; ++iter_a, ++iter_b)
731 {
732 /* assure both ranges have the same number of elements */
733 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
734
735 if (*iter_a < 0 && *iter_b >= 0)
736 {
737 ++fn;
738 }
739 else if (*iter_a < 0 && *iter_b < 0)
740 {
741 ++tn;
742 }
743 else if (*iter_a >= 0 && *iter_b >= 0)
744 {
745 ++tp;
746 }
747 else if (*iter_a >= 0 && *iter_b < 0)
748 {
749 ++fp;
750 }
751 }
752 /* assure both ranges have the same number of elements */
753 checkIteratorsEqual(iter_b, end_b);
754
755 return (tp * tn - fp * fn) / std::sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn));
756 }
757
769 template <typename IteratorType1, typename IteratorType2>
771 IteratorType1 begin_a, IteratorType1 end_a,
772 IteratorType2 begin_b, IteratorType2 end_b)
773 {
774 //no data or different lengths
775 checkIteratorsNotNULL(begin_a, end_a);
776
777 //calculate average
778 SignedSize dist = std::distance(begin_a, end_a);
779 double avg_a = std::accumulate(begin_a, end_a, 0.0) / dist;
780 double avg_b = std::accumulate(begin_b, end_b, 0.0) / dist;
781
782 double numerator = 0;
783 double denominator_a = 0;
784 double denominator_b = 0;
785 IteratorType1 iter_a = begin_a;
786 IteratorType2 iter_b = begin_b;
787 for (; iter_a != end_a; ++iter_a, ++iter_b)
788 {
789 /* assure both ranges have the same number of elements */
790 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
791 double temp_a = *iter_a - avg_a;
792 double temp_b = *iter_b - avg_b;
793 numerator += (temp_a * temp_b);
794 denominator_a += (temp_a * temp_a);
795 denominator_b += (temp_b * temp_b);
796 }
797 /* assure both ranges have the same number of elements */
798 checkIteratorsEqual(iter_b, end_b);
799 return numerator / std::sqrt(denominator_a * denominator_b);
800 }
801
803 template <typename Value>
804 static void computeRank(std::vector<Value> & w)
805 {
806 Size i = 0; // main index
807 Size z = 0; // "secondary" index
808 Value rank = 0;
809 Size n = (w.size() - 1);
810 //store original indices for later
811 std::vector<std::pair<Size, Value> > w_idx;
812 for (Size j = 0; j < w.size(); ++j)
813 {
814 w_idx.push_back(std::make_pair(j, w[j]));
815 }
816 //sort
817 std::sort(w_idx.begin(), w_idx.end(),
818 [](const auto& pair1, const auto& pair2) { return pair1.second < pair2.second; });
819 //replace pairs <orig_index, value> in w_idx by pairs <orig_index, rank>
820 while (i < n)
821 {
822 // test for equality with tolerance:
823 if (fabs(w_idx[i + 1].second - w_idx[i].second) > 0.0000001 * fabs(w_idx[i + 1].second)) // no tie
824 {
825 w_idx[i].second = Value(i + 1);
826 ++i;
827 }
828 else // tie, replace by mean rank
829 {
830 // count number of ties
831 for (z = i + 1; (z <= n) && fabs(w_idx[z].second - w_idx[i].second) <= 0.0000001 * fabs(w_idx[z].second); ++z)
832 {
833 }
834 // compute mean rank of tie
835 rank = 0.5 * (i + z + 1);
836 // replace intensities by rank
837 for (Size v = i; v <= z - 1; ++v)
838 {
839 w_idx[v].second = rank;
840 }
841 i = z;
842 }
843 }
844 if (i == n)
845 w_idx[n].second = Value(n + 1);
846 //restore original order and replace elements of w with their ranks
847 for (Size j = 0; j < w.size(); ++j)
848 {
849 w[w_idx[j].first] = w_idx[j].second;
850 }
851 }
852
864 template <typename IteratorType1, typename IteratorType2>
866 IteratorType1 begin_a, IteratorType1 end_a,
867 IteratorType2 begin_b, IteratorType2 end_b)
868 {
869 //no data or different lengths
870 checkIteratorsNotNULL(begin_a, end_a);
871
872 // store and sort intensities of model and data
873 SignedSize dist = std::distance(begin_a, end_a);
874 std::vector<double> ranks_data;
875 ranks_data.reserve(dist);
876 std::vector<double> ranks_model;
877 ranks_model.reserve(dist);
878 IteratorType1 iter_a = begin_a;
879 IteratorType2 iter_b = begin_b;
880 for (; iter_a != end_a; ++iter_a, ++iter_b)
881 {
882 /* assure both ranges have the same number of elements */
883 checkIteratorsAreValid(iter_b, end_b, iter_a, end_a);
884
885 ranks_model.push_back(*iter_a);
886 ranks_data.push_back(*iter_b);
887 }
888 /* assure both ranges have the same number of elements */
889 checkIteratorsEqual(iter_b, end_b);
890
891 // replace entries by their ranks
892 computeRank(ranks_data);
893 computeRank(ranks_model);
894
895 double mu = double(ranks_data.size() + 1) / 2.; // mean of ranks
896 // Was the following, but I think the above is more correct ... (Clemens)
897 // double mu = (ranks_data.size() + 1) / 2;
898
899 double sum_model_data = 0;
900 double sqsum_data = 0;
901 double sqsum_model = 0;
902
903 for (Int i = 0; i < dist; ++i)
904 {
905 sum_model_data += (ranks_data[i] - mu) * (ranks_model[i] - mu);
906 sqsum_data += (ranks_data[i] - mu) * (ranks_data[i] - mu);
907 sqsum_model += (ranks_model[i] - mu) * (ranks_model[i] - mu);
908 }
909
910 // check for division by zero
911 if (!sqsum_data || !sqsum_model)
912 {
913 return 0;
914 }
915
916 return sum_model_data / (std::sqrt(sqsum_data) * std::sqrt(sqsum_model));
917 }
918
920 template<typename T>
922 {
923 SummaryStatistics() = default;
924
925 // Ctor with data
927 {
928 count = data.size();
929 // Sanity check: avoid core dump if no data points present.
930 if (data.empty())
931 {
932 mean = variance = min = lowerq = median = upperq = max = 0.0;
933 }
934 else
935 {
936 sort(data.begin(), data.end());
937 mean = Math::mean(data.begin(), data.end());
938 variance = Math::variance(data.begin(), data.end(), mean);
939 min = data.front();
940 lowerq = Math::quantile1st(data.begin(), data.end(), true);
941 median = Math::median(data.begin(), data.end(), true);
942 upperq = Math::quantile3rd(data.begin(), data.end(), true);
943 max = data.back();
944 }
945 }
946
947 double mean = 0, variance = 0 , lowerq = 0, median = 0, upperq = 0;
948 typename T::value_type min = 0, max = 0;
949 size_t count = 0;
950 };
951
952 } // namespace Math
953} // namespace OpenMS
954
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:94
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:770
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:717
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:678
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:865
static double quantile3rd(IteratorType begin, IteratorType end, bool sorted=false)
Calculates the third quantile of a range of values.
Definition StatisticFunctions.h:267
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:592
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:235
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:625
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:662
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:556
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:571
double tailFractionAbove(IteratorType begin, IteratorType end, double threshold)
Fraction of values above a threshold.
Definition StatisticFunctions.h:380
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:351
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:804
double winsorizedQuantile(IteratorType begin, IteratorType end, double q, double upper_fence)
Quantile after winsorizing at an upper fence.
Definition StatisticFunctions.h:412
static double variance(IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
Definition StatisticFunctions.h:529
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:471
Result of adaptiveQuantile computation.
Definition StatisticFunctions.h:38
std::string toStr(int i)
Definition StringUtils.h:257
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:922
double lowerq
Definition StatisticFunctions.h:947
double variance
Definition StatisticFunctions.h:947
T::value_type max
Definition StatisticFunctions.h:948
SummaryStatistics(T &data)
Definition StatisticFunctions.h:926
double median
Definition StatisticFunctions.h:947
size_t count
Definition StatisticFunctions.h:949
double mean
Definition StatisticFunctions.h:947
double upperq
Definition StatisticFunctions.h:947
T::value_type min
Definition StatisticFunctions.h:948