statistics::stats_computer1< T > Class Template Reference
Collaboration diagram for statistics::stats_computer1< T >:
[legend]

## Public Member Functions

void | new_val (T x)
double | mean () const
double | variance () const
double | std () const

## Private Attributes

unsigned int | n = 0
double | Ex
double | Ex2
T | K

## Friends

std::istream & | operator>> (std::istream &input, stats_computer1 &stat)

## Detailed Description

### template<typename T>
class statistics::stats_computer1< T >

continuous mean and variance computance using first value as an approximation for the mean. If the first number is much far form the mean, the algorithm becomes very inaccurate to compute variance and standard deviation.

## Member Function Documentation

## mean()

template<typename T >

double statistics::stats_computer1< T >::mean | ( |  | ) | const

inline

return sample mean computed till last sample

{ return K + Ex / n; }

## new_val()

template<typename T >

void statistics::stats_computer1< T >::new_val | ( | T | x | ) |

inline

Constructor

Parameters

  [in] | x | new data sample

{
if (n == 0)
K = x;
n++;
T tmp = x - K;
Ex += tmp;
Ex2 += static_cast<double>(tmp) * tmp;
}

## std()

template<typename T >

double statistics::stats_computer1< T >::std | ( |  | ) | const

inline

return sample standard deviation computed till last sample

{ return std::sqrt(this->variance()); }
statistics::stats_computer1::variance
double variance() const
Definition: realtime_stats.cpp:45
std::sqrt
T sqrt(T... args)
Here is the call graph for this function:

## variance()

template<typename T >

double statistics::stats_computer1< T >::variance | ( |  | ) | const

inline

return data variance computed till last sample

{ return (Ex2 - (Ex * Ex) / n) / (n - 1); }

## Friends And Related Function Documentation

## operator>>

template<typename T >

std::istream& operator>> | ( | std::istream & | input,
|  | stats_computer1< T > & | stat
| ) |  |

friend

short-hand operator to read new sample from input stream
e.g.: `std::cin >> stats1;`

{
T val;
input >> val;
stat.new_val(val);
return input;
}
statistics::stats_computer1::new_val
void new_val(T x)
Definition: realtime_stats.cpp:32

The documentation for this class was generated from the following file:

- math/realtime_stats.cpp