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;
139 template <
typename ProbabilityIterator,
typename CoordinateIterator>
140 void update(ProbabilityIterator
const probability_begin,
141 ProbabilityIterator
const probability_end,
142 CoordinateIterator
const coordinate_begin
146 ProbabilityIterator prob_iter = probability_begin;
147 CoordinateIterator coord_iter = coordinate_begin;
149 for (; prob_iter != probability_end; ++prob_iter, ++coord_iter)
152 mean_ += *prob_iter * *coord_iter;
156 for (prob_iter = probability_begin, coord_iter = coordinate_begin;
157 prob_iter != probability_end;
158 ++prob_iter, ++coord_iter
161 RealType diff = *coord_iter - mean_;
163 variance_ += *prob_iter * diff;
188 coordinate -=
mean();
189 coordinate *= coordinate;
201 return normalDensity_sqrt2pi(coordinate) / sqrt2pi();
210 normalApproximationHelper_(probability, probability.size());
219 typename probability_container::size_type
const size
222 probability.resize(size);
223 normalApproximationHelper_(probability, size);
236 probability.resize(coordinate.size());
237 normalApproximationHelper_(probability, coordinate);
247 os <<
"BasicStatistics: mean=" << arg.
mean() <<
" variance=" << arg.
variance() <<
" sum=" << arg.
sum();
267 typename probability_container::size_type
const size
271 typename coordinate_container::size_type i;
274 for (i = 0; i < size; ++i)
276 gaussSum += normalDensity_sqrt2pi(
RealType(i));
279 for (i = 0; i < size; ++i)
281 probability[i] = normalDensity_sqrt2pi(
RealType(i)) / gaussSum *
sum();
291 typename coordinate_container::size_type i;
292 typename coordinate_container::size_type
const size = coordinate.size();
294 for (i = 0; i < size; ++i)
296 gaussSum += normalDensity_sqrt2pi(coordinate[i]);
299 for (i = 0; i < size; ++i)
301 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:266
RealType normalDensity(RealType const coordinate) const
See normalDensity_sqrt2pi(). Returns the density of the normal distribution at point.
Definition: BasicStatistics.h:199
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:171
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:208
void normalApproximation(probability_container &probability, typename probability_container::size_type const size)
Definition: BasicStatistics.h:218
static RealType sqrt2pi()
Returns sqrt( 2 * pi ), which is useful to normalize the result of normalDensity_sqrt2pi().
Definition: BasicStatistics.h:194
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:170
void update(ProbabilityIterator const probability_begin, ProbabilityIterator const probability_end, CoordinateIterator const coordinate_begin)
This does the actual calculation.
Definition: BasicStatistics.h:140
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:245
RealType sum_
Definition: BasicStatistics.h:258
void normalApproximation(probability_container &probability, coordinate_container const &coordinate)
The argument probability is filled with values according to the normal approximation....
Definition: BasicStatistics.h:232
RealType normalDensity_sqrt2pi(RealType coordinate) const
Returns the density of the normal approximation at point, multiplied by sqrt( 2 * pi )....
Definition: BasicStatistics.h:186
RealType variance() const
Returns the variance.
Definition: BasicStatistics.h:174
std::vector< RealType > probability_container
Definition: BasicStatistics.h:76
void setSum(RealType const &sum)
Definition: BasicStatistics.h:179
void normalApproximationHelper_(probability_container &probability, coordinate_container const &coordinate)
Definition: BasicStatistics.h:286
void clear()
Set sum, mean, and variance to zero.
Definition: BasicStatistics.h:103
RealType sum() const
Returns the sum.
Definition: BasicStatistics.h:178
RealType variance_
Definition: BasicStatistics.h:257
RealType mean_
Definition: BasicStatistics.h:256
void setVariance(RealType const &variance)
Definition: BasicStatistics.h:175
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:133
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:120
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:307
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47