Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_MATH_STATISTICS_ASYMMETRICSTATISTICS_H
00036 #define OPENMS_MATH_STATISTICS_ASYMMETRICSTATISTICS_H
00037
00038 #include <OpenMS/CONCEPT/Types.h>
00039 #include <OpenMS/MATH/STATISTICS/BasicStatistics.h>
00040
00041 #include <vector>
00042 #include <ostream>
00043 #include <cmath>
00044
00045 namespace OpenMS
00046 {
00047 namespace Math
00048 {
00049
00058 template <typename Real = DoubleReal>
00059 class AsymmetricStatistics :
00060 public BasicStatistics<Real>
00061 {
00063 typedef BasicStatistics<Real> Base;
00064 typedef typename Base::RealType RealType;
00065
00066 using Base::clear;
00067 using Base::sum_;
00068 using Base::mean_;
00069 using Base::variance_;
00070
00071 public:
00072
00074 AsymmetricStatistics() :
00075 BasicStatistics<>(),
00076 variance1_(0),
00077 variance2_(0)
00078 {}
00079
00081 RealType variance1() const
00082 {
00083 return variance1_;
00084 }
00085
00087 RealType variance2() const
00088 {
00089 return variance2_;
00090 }
00091
00093 template <typename ProbabilityIterator, typename CoordinateIterator>
00094 void update(ProbabilityIterator const probability_begin,
00095 ProbabilityIterator const probability_end,
00096 CoordinateIterator const coordinate_begin)
00097 {
00098
00099 Base::update(probability_begin, probability_end, coordinate_begin);
00100
00101 const RealType stdev = std::sqrt(variance_);
00102
00103 RealType sum1 = 0;
00104 RealType sum2 = 0;
00105 variance1_ = 0;
00106 variance2_ = 0;
00107 ProbabilityIterator prob_iter = probability_begin;
00108 CoordinateIterator coord_iter = coordinate_begin;
00109 for (; prob_iter != probability_end; ++prob_iter, ++coord_iter)
00110 {
00111 RealType diff = *coord_iter - mean_;
00112 RealType diff_squared = diff * diff;
00113
00114 if (diff_squared > variance_)
00115 {
00116 if (*coord_iter < mean_)
00117 {
00118 variance1_ += (*prob_iter * diff_squared);
00119 sum1 += *prob_iter;
00120 }
00121 else
00122 {
00123 variance2_ += (*prob_iter * diff_squared);
00124 sum2 += *prob_iter;
00125 }
00126 }
00127 else
00128 {
00129 RealType frac = (diff / stdev + 1.) / 2.;
00130 RealType prob_frac = frac * *prob_iter;
00131 variance2_ += prob_frac * diff_squared;
00132 sum2 += prob_frac;
00133 prob_frac = *prob_iter * (1. - frac);
00134 variance1_ += prob_frac * diff_squared;
00135 sum1 += prob_frac;
00136 }
00137 }
00138 variance1_ /= sum1;
00139 variance2_ /= sum2;
00140 return;
00141 }
00142
00143 protected:
00145 RealType variance1_, variance2_;
00146 };
00147
00148 }
00149
00150 }
00151
00152 #endif // OPENMS_MATH_STATISTICS_ASYMMETRICSTATISTICS_H