statistics::stats_computer2< T > Class Template Reference

## Public Member Functions

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

## Private Attributes

unsigned int | n = 0
double | mu = 0
double | var = 0
double | M = 0

## Friends

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

## Detailed Description

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

continuous mean and variance computance using Welford's algorithm (very accurate)

## Member Function Documentation

## mean()

template<typename T >

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

inline

return sample mean computed till last sample

{ return mu; }

## new_val()

template<typename T >

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

inline

Constructor

Parameters

  [in] | x | new data sample

{
n++;
double delta = x - mu;
mu += delta / n;
double delta2 = x - mu;
M += delta * delta2;
}

## std()

template<typename T >

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

inline

return sample standard deviation computed till last sample

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

## variance()

template<typename T >

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

inline

return data variance computed till last sample

{ return M / n; }

## Friends And Related Function Documentation

## operator>>

template<typename T >

std::istream& operator>> | ( | std::istream & | input,
|  | stats_computer2< 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_computer2::new_val
void new_val(T x)
Definition: realtime_stats.cpp:77

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

- math/realtime_stats.cpp