TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
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)

Definition at line 72 of file realtime_stats.cpp.

Member Function Documentation

◆ mean()

template<typename T >
double statistics::stats_computer2< T >::mean ( ) const
inline

return sample mean computed till last sample

Definition at line 86 of file realtime_stats.cpp.

86{ return mu; }

◆ new_val()

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

Constructor

Parameters
[in]xnew data sample

Definition at line 77 of file realtime_stats.cpp.

77 {
78 n++;
79 double delta = x - mu;
80 mu += delta / n;
81 double delta2 = x - mu;
82 M += delta * delta2;
83 }

◆ std()

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

return sample standard deviation computed till last sample

Definition at line 92 of file realtime_stats.cpp.

92{ return std::sqrt(this->variance()); }

◆ variance()

template<typename T >
double statistics::stats_computer2< T >::variance ( ) const
inline

return data variance computed till last sample

Definition at line 89 of file realtime_stats.cpp.

89{ return M / n; }

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

Definition at line 97 of file realtime_stats.cpp.

98 {
99 T val;
100 input >> val;
101 stat.new_val(val);
102 return input;
103 }

Member Data Documentation

◆ M

template<typename T >
double statistics::stats_computer2< T >::M = 0
private

Definition at line 107 of file realtime_stats.cpp.

◆ mu

template<typename T >
double statistics::stats_computer2< T >::mu = 0
private

Definition at line 107 of file realtime_stats.cpp.

◆ n

template<typename T >
unsigned int statistics::stats_computer2< T >::n = 0
private

Definition at line 106 of file realtime_stats.cpp.

◆ var

template<typename T >
double statistics::stats_computer2< T >::var = 0
private

Definition at line 107 of file realtime_stats.cpp.


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