Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
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
 
K
 

Friends

std::istreamoperator>> (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

42{ return K + Ex / n; }

◆ new_val()

template<typename T >
void statistics::stats_computer1< T >::new_val ( T x)
inline

Constructor

Parameters
[in]xnew data sample
32 {
33 if (n == 0)
34 K = x;
35 n++;
36 T tmp = x - K;
37 Ex += tmp;
38 Ex2 += static_cast<double>(tmp) * tmp;
39 }

◆ std()

template<typename T >
double statistics::stats_computer1< T >::std ( ) const
inline

return sample standard deviation computed till last sample

48{ return std::sqrt(this->variance()); }
double variance() const
Definition realtime_stats.cpp:45
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

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

Friends And Related Symbol 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;

54 {
55 T val;
56 input >> val;
57 stat.new_val(val);
58 return input;
59 }
void new_val(T x)
Definition realtime_stats.cpp:32

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