9 #ifndef _STATISTICS_CALCULATOR_H_
10 #define _STATISTICS_CALCULATOR_H_
32 template <
typename Type>
58 const value_type delta(datum -
_mean);
59 _mean += (delta /
static_cast<value_type
>(
_N));
72 template <
class InputIterator>
95 return (
_tmp/static_cast<value_type>(
_N - 1));
156 template <
typename Type>
173 typedef typename std::iterator_traits<iterator_t>::difference_type
count_type;
201 template <
class InputIterator>
204 while (first != last)
302 sort(c.begin(),c.end());
303 iterator_t lowPos(c.begin());
304 iterator_t upPos(c.end());
306 bool outliersdetected(
false);
314 iterator_t newLowPos(lower_bound(c.begin(), c.end(), lowBound));
315 iterator_t newUpPos(upper_bound (c.begin(), c.end(), upBound));
318 outliersdetected = ( newLowPos != lowPos || newUpPos != upPos);
323 while (outliersdetected);
372 template <
typename Type>
386 nbrAverages(nAverages);
396 _mean = (1.f - _alpha)*
mean + _alpha*datum;
443 _alpha = (2./(1.+
static_cast<value_type
>(nAverages)));
470 template <
typename Type>
504 template <
class InputIterator>
507 while (first != last)
540 static value_type
median(
const container_type &container)
542 container_type cc(container);
543 const size_t medianpos(0.5*cc.size());
544 std::nth_element(cc.begin(), cc.begin() + medianpos, cc.end());
545 const value_type medianval(cc[medianpos]);
size_t counter_type
define the type of the counter
void addDatum(const value_type &datum)
add a datum to the distribution
value_type _tmp
the current intermediate value that one calcs the stdv from
counter_type _N
counter to see how many values have been added to the statistics
Type value_type
define the value type
void updateStat()
update the statistic values
Type _snr
the signal to noise ratio that will detectect outliers
counter_type count() const
retrieve the number of datum that have been added
count_type nbrUpperOutliers()
retrieve the number of outliers higher than the distribution used
value_type stdv() const
retrieve the standart deviation of the distribution
value_type mean()
retrieve the mean of the distribution without outliers
statistics calculator for a cummulative statistic, removes outliers
bool _firstdatum
flag to see whether first datum is added
Type value_type
define the value type
count_type _nLowerOutliers
the number of lower outliers
statistics calculator for a cummulative statistic
void reset()
reset the statistics
value_type _sum
the sum of all dati
CummulativeStatisticsCalculator()
default constructor
value_type mean() const
retrieve the mean of the distribution
statistics calculator for a exponential moving statistics
count_type nbrPointsUsed()
retrieve the number of points used in the statistics
value_type mean() const
retrieve the mean of the distribution
value_type _mean
the current mean value
value_type variance() const
retrieve the variance of the distribution
count_type _nPoints
the number of points included in the statistics calculation
value_type _mean
the current mean value
value_type _stdv
the stdv value
bool _containerChanged
flag to show whether the statistic values have to be updated
CummulativeStatisticsNoOutlier(const value_type &snr)
constructor sets the signal to noise ratio
void addDistribution(InputIterator first, InputIterator last)
add a number of dati to the distribution
void addDatum(const value_type &datum)
add a datum to the distribution
value_type sum() const
retrieve the sum of all dati that have been added
void nbrAverages(unsigned int nAverages)
set the nbr of averages
count_type _nUpperOutliers
the number of upper outliers
CummulativeStatisticsCalculator< value_type > statistics_t
define the statistics
void setDistribution(const container_type &distribution)
substitute the internal container with an outside one
void addDatum(const value_type &datum)
add a datum to the container
container_type::iterator iterator_t
define a const iterator of the container
Type _stdv
the stdv without outliers
void reset()
reset the container
count_type nbrLowerOutliers()
retrieve the number of outliers lower than the distribution used
Type value_type
define the value type
void addDistribution(InputIterator first, InputIterator last)
add a number of dati to the distribution
Type _mean
the mean without outliers
void reset()
reset the statistics
value_type stdv()
retrieve the standart deviation of the distribution
statistics_t _stat
the statistics calculator
std::vector< value_type > container_type
define the type of container used for the values
value_type stdv() const
retrieve the standart deviation of the distribution
value_type variance() const
retrieve the variance of the distribution
MovingStatisticsCalculator(unsigned int nAverages=200)
constructor
std::iterator_traits< iterator_t >::difference_type count_type
define number of elements
count_type nbrOutliers()
retrieve the total number of outliers
container_type _container
container to store the values in
value_type _alpha
how much should the current datum be weighted