40 template <
typename RealT =
double>
63 variance_(arg.variance_),
86 template <
typename ProbabilityIterator>
87 void update(ProbabilityIterator probability_begin,
88 ProbabilityIterator
const probability_end
93 ProbabilityIterator iter = probability_begin;
95 for (; iter != probability_end; ++iter, ++pos)
102 for (iter = probability_begin, pos = 0; iter != probability_end; ++iter, ++pos)
106 variance_ += *iter * diff;
110 if (sum_ == 0 && (std::isnan(mean_) || std::isinf(mean_)) )
119 template <
typename ProbabilityIterator,
typename CoordinateIterator>
120 void update(ProbabilityIterator
const probability_begin,
121 ProbabilityIterator
const probability_end,
122 CoordinateIterator
const coordinate_begin
126 ProbabilityIterator prob_iter = probability_begin;
127 CoordinateIterator coord_iter = coordinate_begin;
129 for (; prob_iter != probability_end; ++prob_iter, ++coord_iter)
132 mean_ += *prob_iter * *coord_iter;
136 for (prob_iter = probability_begin, coord_iter = coordinate_begin;
137 prob_iter != probability_end;
138 ++prob_iter, ++coord_iter
141 RealType diff = *coord_iter - mean_;
143 variance_ += *prob_iter * diff;
168 coordinate -=
mean();
169 coordinate *= coordinate;
181 return normalDensity_sqrt2pi(coordinate) / sqrt2pi();
190 normalApproximationHelper_(probability, probability.size());
199 typename probability_container::size_type
const size
202 probability.resize(size);
203 normalApproximationHelper_(probability, size);
216 probability.resize(coordinate.size());
217 normalApproximationHelper_(probability, coordinate);
227 os <<
"BasicStatistics: mean=" << arg.
mean() <<
" variance=" << arg.
variance() <<
" sum=" << arg.
sum();
247 typename probability_container::size_type
const size
251 typename coordinate_container::size_type i;
254 for (i = 0; i < size; ++i)
256 gaussSum += normalDensity_sqrt2pi(
RealType(i));
259 for (i = 0; i < size; ++i)
261 probability[i] = normalDensity_sqrt2pi(
RealType(i)) / gaussSum *
sum();
271 typename coordinate_container::size_type i;
272 typename coordinate_container::size_type
const size = coordinate.size();
274 for (i = 0; i < size; ++i)
276 gaussSum += normalDensity_sqrt2pi(coordinate[i]);
279 for (i = 0; i < size; ++i)
281 probability[i] = normalDensity_sqrt2pi(coordinate[i]) / gaussSum *
sum();
Calculates some basic statistical parameters of a distribution: sum, mean, variance,...
Definition: BasicStatistics.h:43
void normalApproximationHelper_(probability_container &probability, typename probability_container::size_type const size)
Definition: BasicStatistics.h:246
RealType normalDensity(RealType const coordinate) const
See normalDensity_sqrt2pi(). Returns the density of the normal distribution at point.
Definition: BasicStatistics.h:179
std::vector< RealType > coordinate_container
Definition: BasicStatistics.h:51
BasicStatistics()
Default constructor.
Definition: BasicStatistics.h:54
BasicStatistics(BasicStatistics const &arg)
Copy constructor.
Definition: BasicStatistics.h:61
void setMean(RealType const &mean)
Definition: BasicStatistics.h:151
RealT RealType
The real type specified as template argument.
Definition: BasicStatistics.h:48
void normalApproximation(probability_container &probability)
The argument probability is filled with values according to the normal approximation....
Definition: BasicStatistics.h:188
void normalApproximation(probability_container &probability, typename probability_container::size_type const size)
Definition: BasicStatistics.h:198
static RealType sqrt2pi()
Returns sqrt( 2 * pi ), which is useful to normalize the result of normalDensity_sqrt2pi().
Definition: BasicStatistics.h:174
void update(ProbabilityIterator probability_begin, ProbabilityIterator const probability_end)
This does the actual calculation.
Definition: BasicStatistics.h:87
RealType mean() const
Returns the mean.
Definition: BasicStatistics.h:150
void update(ProbabilityIterator const probability_begin, ProbabilityIterator const probability_end, CoordinateIterator const coordinate_begin)
This does the actual calculation.
Definition: BasicStatistics.h:120
BasicStatistics & operator=(BasicStatistics const &arg)
Assignment.
Definition: BasicStatistics.h:68
friend std::ostream & operator<<(std::ostream &os, BasicStatistics &arg)
A convenient overload for debugging purposes.
Definition: BasicStatistics.h:225
RealType sum_
Definition: BasicStatistics.h:238
void normalApproximation(probability_container &probability, coordinate_container const &coordinate)
The argument probability is filled with values according to the normal approximation....
Definition: BasicStatistics.h:212
RealType normalDensity_sqrt2pi(RealType coordinate) const
Returns the density of the normal approximation at point, multiplied by sqrt( 2 * pi )....
Definition: BasicStatistics.h:166
RealType variance() const
Returns the variance.
Definition: BasicStatistics.h:154
std::vector< RealType > probability_container
Definition: BasicStatistics.h:50
void setSum(RealType const &sum)
Definition: BasicStatistics.h:159
void normalApproximationHelper_(probability_container &probability, coordinate_container const &coordinate)
Definition: BasicStatistics.h:266
void clear()
Set sum, mean, and variance to zero.
Definition: BasicStatistics.h:77
RealType sum() const
Returns the sum.
Definition: BasicStatistics.h:158
RealType variance_
Definition: BasicStatistics.h:237
RealType mean_
Definition: BasicStatistics.h:236
void setVariance(RealType const &variance)
Definition: BasicStatistics.h:155
static double mean(IteratorType begin, IteratorType end)
Calculates the mean of a range of values.
Definition: StatisticFunctions.h:94
static double sum(IteratorType begin, IteratorType end)
Calculates the sum of a range of values.
Definition: StatisticFunctions.h:81
static double variance(IteratorType begin, IteratorType end, double mean=std::numeric_limits< double >::max())
Definition: StatisticFunctions.h:268
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19