Running_stat

Classes

class  arma_counter< eT >
class  running_stat< eT >
 Class for keeping statistics of a continuously sampled process / signal. Useful if the storage of individual samples is not necessary or desired. Also useful if the number of samples is not known beforehand or exceeds available memory. More...
class  running_stat_aux

Functions

 arma_counter::~arma_counter ()
 arma_counter::arma_counter ()
const arma_counterarma_counter::operator++ ()
void arma_counter::operator++ (int)
void arma_counter::reset ()
eT arma_counter::value () const
eT arma_counter::value_plus_1 () const
eT arma_counter::value_minus_1 () const
 running_stat::~running_stat ()
 running_stat::running_stat ()
void running_stat::operator() (const T sample)
 update statistics to reflect new sample
void running_stat::operator() (const std::complex< T > &sample)
 update statistics to reflect new sample (version for complex numbers)
void running_stat::reset ()
 set all statistics to zero
eT running_stat::mean () const
 mean or average value
running_stat::var (const u32 norm_type=0) const
 variance
running_stat::stddev (const u32 norm_type=0) const
 standard deviation
eT running_stat::min () const
 minimum value
eT running_stat::max () const
 maximum value
template<typename eT >
static void running_stat_aux::update_stats (running_stat< eT > &x, const eT sample)
 update statistics to reflect new sample
template<typename T >
static void running_stat_aux::update_stats (running_stat< std::complex< T > > &x, const T sample)
 update statistics to reflect new sample (version for complex numbers)
template<typename T >
static void running_stat_aux::update_stats (running_stat< std::complex< T > > &x, const std::complex< T > &sample)
 alter statistics to reflect new sample (version for complex numbers)

Function Documentation

template<typename eT >
arma_counter< eT >::~arma_counter (  )  [inline, inherited]

Definition at line 23 of file running_stat_meat.hpp.

00024   {
00025   arma_extra_debug_sigprint_this(this);
00026   }

template<typename eT >
arma_counter< eT >::arma_counter (  )  [inline, inherited]

Definition at line 32 of file running_stat_meat.hpp.

00033   : d_count( eT(0))
00034   , i_count(u32(0))
00035   {
00036   arma_extra_debug_sigprint_this(this);
00037   }

template<typename eT >
const arma_counter< eT > & arma_counter< eT >::operator++ (  )  [inline, inherited]

Definition at line 44 of file running_stat_meat.hpp.

References arma_counter< eT >::d_count, and arma_counter< eT >::i_count.

Referenced by arma_counter< eT >::operator++().

00045   {
00046   const u32 max_val = 0xffffffff;
00047   
00048   if(i_count < max_val)
00049     {
00050     i_count++;
00051     }
00052   else
00053     {
00054     d_count += eT(max_val);
00055     i_count =  1;
00056     }
00057   
00058   return *this;
00059   }

template<typename eT >
void arma_counter< eT >::operator++ ( int   )  [inline, inherited]

Definition at line 66 of file running_stat_meat.hpp.

References arma_counter< eT >::operator++().

00067   {
00068   operator++();
00069   }

template<typename eT >
void arma_counter< eT >::reset (  )  [inline, inherited]

Definition at line 76 of file running_stat_meat.hpp.

References arma_counter< eT >::d_count, and arma_counter< eT >::i_count.

Referenced by running_stat_vec< eT >::reset(), and running_stat< eT >::reset().

00077   {
00078   d_count =  eT(0);
00079   i_count = u32(0);
00080   }

template<typename eT >
eT arma_counter< eT >::value (  )  const [inline, inherited]
template<typename eT >
eT arma_counter< eT >::value_plus_1 (  )  const [inline, inherited]

Definition at line 98 of file running_stat_meat.hpp.

References arma_counter< eT >::d_count, and arma_counter< eT >::i_count.

Referenced by running_stat_vec_aux::update_stats(), and running_stat_aux::update_stats().

00100   {
00101   const u32 max_val = 0xffffffff;
00102   
00103   if(i_count < max_val)
00104     {
00105     return d_count + eT(i_count + 1);
00106     }
00107   else
00108     {
00109     return d_count + eT(max_val) + eT(1);
00110     }
00111   }

template<typename eT >
eT arma_counter< eT >::value_minus_1 (  )  const [inline, inherited]

Definition at line 118 of file running_stat_meat.hpp.

References arma_counter< eT >::d_count, and arma_counter< eT >::i_count.

Referenced by running_stat_vec< eT >::cov(), running_stat_vec_aux::update_stats(), running_stat_aux::update_stats(), running_stat_vec< eT >::var(), and running_stat< eT >::var().

00120   {
00121   if(i_count > 0)
00122     {
00123     return d_count + eT(i_count - 1);
00124     }
00125   else
00126     {
00127     return d_count - eT(1);
00128     }
00129   }

template<typename eT >
running_stat< eT >::~running_stat (  )  [inline, inherited]

Definition at line 138 of file running_stat_meat.hpp.

00139   {
00140   arma_extra_debug_sigprint_this(this);
00141   }

template<typename eT >
running_stat< eT >::running_stat (  )  [inline, inherited]

Definition at line 146 of file running_stat_meat.hpp.

00147   : r_mean      (                          eT(0))
00148   , r_var       (typename running_stat<eT>::T(0))
00149   , min_val     (                          eT(0))
00150   , max_val     (                          eT(0))
00151   , min_val_norm(typename running_stat<eT>::T(0))
00152   , max_val_norm(typename running_stat<eT>::T(0))
00153   {
00154   arma_extra_debug_sigprint_this(this);
00155   }

template<typename eT >
void running_stat< eT >::operator() ( const T  sample  )  [inline, inherited]

update statistics to reflect new sample

Definition at line 163 of file running_stat_meat.hpp.

References arma_check(), arma_isfinite(), and running_stat_aux::update_stats().

00164   {
00165   arma_extra_debug_sigprint();
00166   
00167   arma_check( (arma_isfinite(sample) == false), "running_stat: non-finite sample given" );
00168 
00169   running_stat_aux::update_stats(*this, sample);
00170   }

template<typename eT >
void running_stat< eT >::operator() ( const std::complex< T > &  sample  )  [inline, inherited]

update statistics to reflect new sample (version for complex numbers)

Definition at line 178 of file running_stat_meat.hpp.

References arma_check(), arma_isfinite(), and running_stat_aux::update_stats().

00179   {
00180   arma_extra_debug_sigprint();
00181   
00182   isnt_same_type<eT, std::complex< typename running_stat<eT>::T > >::check();
00183   
00184   arma_check( (arma_isfinite(sample) == false), "running_stat: non-finite sample given" );
00185   
00186   running_stat_aux::update_stats(*this, sample);
00187   }

template<typename eT >
void running_stat< eT >::reset (  )  [inline, inherited]

set all statistics to zero

Definition at line 195 of file running_stat_meat.hpp.

References running_stat< eT >::counter, running_stat< eT >::max_val, running_stat< eT >::max_val_norm, running_stat< eT >::min_val, running_stat< eT >::min_val_norm, running_stat< eT >::r_mean, running_stat< eT >::r_var, and arma_counter< eT >::reset().

00196   {
00197   arma_extra_debug_sigprint();
00198   
00199   typedef typename running_stat<eT>::T T;
00200   
00201   counter.reset();
00202   
00203   r_mean       = eT(0);
00204   r_var        =  T(0);
00205   
00206   min_val      = eT(0);
00207   max_val      = eT(0);
00208   
00209   min_val_norm =  T(0);
00210   max_val_norm =  T(0);
00211   }

template<typename eT >
eT running_stat< eT >::mean (  )  const [inline, inherited]

mean or average value

Definition at line 219 of file running_stat_meat.hpp.

References running_stat< eT >::r_mean.

00221   {
00222   arma_extra_debug_sigprint();
00223   
00224   return r_mean;
00225   }

template<typename eT >
running_stat< eT >::T running_stat< eT >::var ( const u32  norm_type = 0  )  const [inline, inherited]

variance

Definition at line 233 of file running_stat_meat.hpp.

References running_stat< eT >::counter, running_stat< eT >::r_var, arma_counter< eT >::value(), and arma_counter< eT >::value_minus_1().

00235   {
00236   arma_extra_debug_sigprint();
00237   
00238   const T N = counter.value();
00239   
00240   if(N > T(1))
00241     {
00242     if(norm_type == 0)
00243       {
00244       return r_var;
00245       }
00246     else
00247       {
00248       const T N_minus_1 = counter.value_minus_1();
00249       return (N_minus_1/N) * r_var;
00250       }
00251     }
00252   else
00253     {
00254     return T(0);
00255     }
00256   }

template<typename eT >
running_stat< eT >::T running_stat< eT >::stddev ( const u32  norm_type = 0  )  const [inline, inherited]

standard deviation

Definition at line 264 of file running_stat_meat.hpp.

References sqrt().

00266   {
00267   arma_extra_debug_sigprint();
00268 
00269   return std::sqrt( (*this).var(norm_type) );
00270   }

template<typename eT >
eT running_stat< eT >::min (  )  const [inline, inherited]

minimum value

Definition at line 278 of file running_stat_meat.hpp.

References running_stat< eT >::min_val.

00280   {
00281   arma_extra_debug_sigprint();
00282   
00283   return min_val;
00284   }

template<typename eT >
eT running_stat< eT >::max (  )  const [inline, inherited]

maximum value

Definition at line 292 of file running_stat_meat.hpp.

References running_stat< eT >::max_val.

00294   {
00295   arma_extra_debug_sigprint();
00296 
00297   return max_val;
00298   }

template<typename eT >
void running_stat_aux::update_stats ( running_stat< eT > &  x,
const eT  sample 
) [inline, static, inherited]

update statistics to reflect new sample

Definition at line 306 of file running_stat_meat.hpp.

References running_stat< eT >::counter, running_stat< eT >::max_val, running_stat< eT >::min_val, running_stat< eT >::r_mean, running_stat< eT >::r_var, arma_counter< eT >::value(), arma_counter< eT >::value_minus_1(), and arma_counter< eT >::value_plus_1().

Referenced by running_stat< eT >::operator()(), and running_stat_aux::update_stats().

00307   {
00308   arma_extra_debug_sigprint();
00309   
00310   typedef typename running_stat<eT>::T T;
00311   
00312   const T N = x.counter.value();
00313   
00314   if(N > T(0))
00315     {
00316     if(sample < x.min_val)
00317       {
00318       x.min_val = sample;
00319       }
00320     
00321     if(sample > x.max_val)
00322       {
00323       x.max_val = sample;
00324       }
00325     
00326     const T  N_plus_1   = x.counter.value_plus_1();
00327     const T  N_minus_1  = x.counter.value_minus_1();
00328     
00329     // note: variance has to be updated before the mean
00330     
00331     const eT tmp = sample - x.r_mean;
00332     
00333     x.r_var  = N_minus_1/N * x.r_var + (tmp*tmp)/N_plus_1;
00334     
00335     x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1;
00336     //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1;
00337     //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1;
00338     }
00339   else
00340     {
00341     x.r_mean  = sample;
00342     x.min_val = sample;
00343     x.max_val = sample;
00344     
00345     // r_var is initialised to zero
00346     // in the constructor and reset()
00347     }
00348   
00349   x.counter++;
00350   }

template<typename T >
void running_stat_aux::update_stats ( running_stat< std::complex< T > > &  x,
const T  sample 
) [inline, static, inherited]

update statistics to reflect new sample (version for complex numbers)

Definition at line 358 of file running_stat_meat.hpp.

References running_stat_aux::update_stats().

00359   {
00360   arma_extra_debug_sigprint();
00361 
00362   running_stat_aux::update_stats(x, std::complex<T>(sample));
00363   }

template<typename T >
void running_stat_aux::update_stats ( running_stat< std::complex< T > > &  x,
const std::complex< T > &  sample 
) [inline, static, inherited]

alter statistics to reflect new sample (version for complex numbers)

Definition at line 371 of file running_stat_meat.hpp.

References norm().

00372   {
00373   arma_extra_debug_sigprint();
00374   
00375   typedef typename std::complex<T> eT;
00376   
00377   const T sample_norm = std::norm(sample);
00378   const T N           = x.counter.value();
00379   
00380   if(N > T(0))
00381     {
00382     if(sample_norm < x.min_val_norm)
00383       {
00384       x.min_val_norm = sample_norm;
00385       x.min_val      = sample;
00386       }
00387     
00388     if(sample_norm > x.max_val_norm)
00389       {
00390       x.max_val_norm = sample_norm;
00391       x.max_val      = sample;
00392       }
00393     
00394     const T  N_plus_1   = x.counter.value_plus_1();
00395     const T  N_minus_1  = x.counter.value_minus_1();
00396     
00397     x.r_var = N_minus_1/N * x.r_var + std::norm(sample - x.r_mean)/N_plus_1;
00398     
00399     x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1;
00400     //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1;
00401     //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1;
00402     }
00403   else
00404     {
00405     x.r_mean       = sample;
00406     x.min_val      = sample;
00407     x.max_val      = sample;
00408     x.min_val_norm = sample_norm;
00409     x.max_val_norm = sample_norm;
00410     
00411     // r_var is initialised to zero
00412     // in the constructor and reset()
00413     }
00414   
00415   x.counter++;
00416   }