66 template <
typename RealT =
double>
89 variance_(arg.variance_),
112 template <
typename ProbabilityIterator>
113 void update(ProbabilityIterator probability_begin,
114 ProbabilityIterator
const probability_end
119 ProbabilityIterator iter = probability_begin;
121 for (; iter != probability_end; ++iter, ++pos)
124 mean_ += *iter * pos;
128 for (iter = probability_begin, pos = 0; iter != probability_end; ++iter, ++pos)
132 variance_ += *iter * diff;
136 if (sum_ == 0 && (std::isnan(mean_) || std::isinf(mean_)) )
145 template <
typename ProbabilityIterator,
typename CoordinateIterator>
146 void update(ProbabilityIterator
const probability_begin,
147 ProbabilityIterator
const probability_end,
148 CoordinateIterator
const coordinate_begin
152 ProbabilityIterator prob_iter = probability_begin;
153 CoordinateIterator coord_iter = coordinate_begin;
155 for (; prob_iter != probability_end; ++prob_iter, ++coord_iter)
158 mean_ += *prob_iter * *coord_iter;
162 for (prob_iter = probability_begin, coord_iter = coordinate_begin;
163 prob_iter != probability_end;
164 ++prob_iter, ++coord_iter
167 RealType diff = *coord_iter - mean_;
169 variance_ += *prob_iter * diff;
194 coordinate -=
mean();
195 coordinate *= coordinate;
207 return normalDensity_sqrt2pi(coordinate) / sqrt2pi();
216 normalApproximationHelper_(probability, probability.size());
225 typename probability_container::size_type
const size
228 probability.resize(size);
229 normalApproximationHelper_(probability, size);
242 probability.resize(coordinate.size());
243 normalApproximationHelper_(probability, coordinate);
253 os <<
"BasicStatistics: mean=" << arg.
mean() <<
" variance=" << arg.
variance() <<
" sum=" << arg.
sum();
273 typename probability_container::size_type
const size
277 typename coordinate_container::size_type i;
280 for (i = 0; i < size; ++i)
282 gaussSum += normalDensity_sqrt2pi(
RealType(i));
285 for (i = 0; i < size; ++i)
287 probability[i] = normalDensity_sqrt2pi(
RealType(i)) / gaussSum *
sum();
297 typename coordinate_container::size_type i;
298 typename coordinate_container::size_type
const size = coordinate.size();
300 for (i = 0; i < size; ++i)
302 gaussSum += normalDensity_sqrt2pi(coordinate[i]);
305 for (i = 0; i < size; ++i)
307 probability[i] = normalDensity_sqrt2pi(coordinate[i]) / gaussSum *
sum();
Calculates some basic statistical parameters of a distribution: sum, mean, variance,...
Definition: BasicStatistics.h:69
void normalApproximationHelper_(probability_container &probability, typename probability_container::size_type const size)
Definition: BasicStatistics.h:272
RealType normalDensity(RealType const coordinate) const
See normalDensity_sqrt2pi(). Returns the density of the normal distribution at point.
Definition: BasicStatistics.h:205
std::vector< RealType > coordinate_container
Definition: BasicStatistics.h:77
BasicStatistics()
Default constructor.
Definition: BasicStatistics.h:80
BasicStatistics(BasicStatistics const &arg)
Copy constructor.
Definition: BasicStatistics.h:87
void setMean(RealType const &mean)
Definition: BasicStatistics.h:177
RealT RealType
The real type specified as template argument.
Definition: BasicStatistics.h:74
void normalApproximation(probability_container &probability)
The argument probability is filled with values according to the normal approximation....
Definition: BasicStatistics.h:214
void normalApproximation(probability_container &probability, typename probability_container::size_type const size)
Definition: BasicStatistics.h:224
static RealType sqrt2pi()
Returns sqrt( 2 * pi ), which is useful to normalize the result of normalDensity_sqrt2pi().
Definition: BasicStatistics.h:200
void update(ProbabilityIterator probability_begin, ProbabilityIterator const probability_end)
This does the actual calculation.
Definition: BasicStatistics.h:113
RealType mean() const
Returns the mean.
Definition: BasicStatistics.h:176
void update(ProbabilityIterator const probability_begin, ProbabilityIterator const probability_end, CoordinateIterator const coordinate_begin)
This does the actual calculation.
Definition: BasicStatistics.h:146
BasicStatistics & operator=(BasicStatistics const &arg)
Assignment.
Definition: BasicStatistics.h:94
friend std::ostream & operator<<(std::ostream &os, BasicStatistics &arg)
A convenient overload for debugging purposes.
Definition: BasicStatistics.h:251
RealType sum_
Definition: BasicStatistics.h:264
void normalApproximation(probability_container &probability, coordinate_container const &coordinate)
The argument probability is filled with values according to the normal approximation....
Definition: BasicStatistics.h:238
RealType normalDensity_sqrt2pi(RealType coordinate) const
Returns the density of the normal approximation at point, multiplied by sqrt( 2 * pi )....
Definition: BasicStatistics.h:192
RealType variance() const
Returns the variance.
Definition: BasicStatistics.h:180
std::vector< RealType > probability_container
Definition: BasicStatistics.h:76
void setSum(RealType const &sum)
Definition: BasicStatistics.h:185
void normalApproximationHelper_(probability_container &probability, coordinate_container const &coordinate)
Definition: BasicStatistics.h:292
void clear()
Set sum, mean, and variance to zero.
Definition: BasicStatistics.h:103
RealType sum() const
Returns the sum.
Definition: BasicStatistics.h:184
RealType variance_
Definition: BasicStatistics.h:263
RealType mean_
Definition: BasicStatistics.h:262
void setVariance(RealType const &variance)
Definition: BasicStatistics.h:181
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:120
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:107
static double variance(IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
Calculates the variance of a range of values.
Definition: StatisticFunctions.h:294
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48