Running_stat


Classes

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

 running_stat::running_stat ()
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)
template<typename eT >
static eT running_stat_aux::var (const running_stat< eT > &x, const u32 norm_type=0)
 variance
template<typename T >
static T running_stat_aux::var (const running_stat< std::complex< T > > &x, const u32 norm_type=0)
 variance (version for complex numbers)

Function Documentation

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

Definition at line 22 of file running_stat_meat.hpp.

00023   : N           (typename running_stat<eT>::T(0))
00024   , acc1        (                          eT(0))
00025   , acc2        (typename running_stat<eT>::T(0))
00026   , min_val     (                          eT(0))
00027   , max_val     (                          eT(0))
00028   , min_val_norm(typename running_stat<eT>::T(0))
00029   , max_val_norm(typename running_stat<eT>::T(0))
00030   {
00031   arma_extra_debug_sigprint_this(this);
00032   }

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

set all statistics to zero

Definition at line 68 of file running_stat_meat.hpp.

References running_stat< eT >::acc1, running_stat< eT >::acc2, running_stat< eT >::max_val, running_stat< eT >::max_val_norm, running_stat< eT >::min_val, running_stat< eT >::min_val_norm, and running_stat< eT >::N.

00069   {
00070   arma_extra_debug_sigprint();
00071 
00072   typedef typename running_stat<eT>::T T;
00073   
00074   N            =  T(0);
00075   
00076   acc1         = eT(0);
00077   acc2         =  T(0);
00078   
00079   min_val      = eT(0);
00080   max_val      = eT(0);
00081   
00082   min_val_norm =  T(0);
00083   max_val_norm =  T(0);
00084   }

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

mean or average value

Definition at line 92 of file running_stat_meat.hpp.

References running_stat< eT >::acc1, and running_stat< eT >::N.

00093   {
00094   arma_extra_debug_sigprint();
00095 
00096   typedef typename running_stat<eT>::T T;
00097   
00098   if(N > T(0))
00099     {
00100     return acc1 / N;
00101     }
00102   else
00103     {
00104     return eT(0);
00105     }
00106   }

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

variance

Definition at line 114 of file running_stat_meat.hpp.

00115   {
00116   arma_extra_debug_sigprint();
00117 
00118   return running_stat_aux::var(*this, norm_type);
00119   }

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

standard deviation

Definition at line 127 of file running_stat_meat.hpp.

References sqrt(), and running_stat_aux::var().

00128   {
00129   arma_extra_debug_sigprint();
00130 
00131   return std::sqrt( running_stat_aux::var(*this, norm_type) );
00132   }

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

minimum value

Definition at line 140 of file running_stat_meat.hpp.

References running_stat< eT >::min_val.

00141   {
00142   arma_extra_debug_sigprint();
00143 
00144   return min_val;
00145   }

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

maximum value

Definition at line 153 of file running_stat_meat.hpp.

References running_stat< eT >::max_val.

00154   {
00155   arma_extra_debug_sigprint();
00156 
00157   return max_val;
00158   }

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 166 of file running_stat_meat.hpp.

References running_stat< eT >::acc1, running_stat< eT >::acc2, running_stat< eT >::max_val, running_stat< eT >::min_val, and running_stat< eT >::N.

Referenced by running_stat_aux::update_stats().

00167   {
00168   arma_extra_debug_sigprint();
00169 
00170   if(x.N > eT(0))
00171     {
00172     if(sample < x.min_val)
00173       {
00174       x.min_val = sample;
00175       }
00176     
00177     if(sample > x.max_val)
00178       {
00179       x.max_val = sample;
00180       }
00181     }
00182   else
00183     {
00184     x.min_val = sample;
00185     x.max_val = sample;
00186     }
00187   
00188   x.N++;
00189   
00190   x.acc1 += sample;
00191   x.acc2 += sample*sample;
00192   }

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 200 of file running_stat_meat.hpp.

References running_stat_aux::update_stats().

00201   {
00202   arma_extra_debug_sigprint();
00203 
00204   running_stat_aux::update_stats(x, std::complex<T>(sample));
00205   }

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 213 of file running_stat_meat.hpp.

References norm().

00214   {
00215   arma_extra_debug_sigprint();
00216 
00217   const T sample_norm = std::norm(sample);
00218   
00219   if(x.N > T(0))
00220     {
00221     if(sample_norm < x.min_val_norm)
00222       {
00223       x.min_val_norm = sample_norm;
00224       x.min_val      = sample;
00225       }
00226     
00227     if(sample_norm > x.max_val_norm)
00228       {
00229       x.max_val_norm = sample_norm;
00230       x.max_val      = sample;
00231       }
00232     }
00233   else
00234     {
00235     x.min_val      = sample;
00236     x.max_val      = sample;
00237     x.min_val_norm = sample_norm;
00238     x.max_val_norm = sample_norm;
00239     }
00240   
00241   x.N++;
00242   
00243   x.acc1 += sample;
00244   x.acc2 += sample_norm;
00245   }

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

variance

Definition at line 253 of file running_stat_meat.hpp.

References running_stat< eT >::acc1, running_stat< eT >::acc2, and running_stat< eT >::N.

Referenced by running_stat< eT >::stddev().

00254   {
00255   arma_extra_debug_sigprint();
00256 
00257   if(x.N > eT(1))
00258     {
00259     const eT norm_val = (norm_type == 0) ? (x.N-eT(1)) : x.N;
00260     const eT var_val  = (x.acc2 - x.acc1*x.acc1/x.N) / norm_val;
00261     return var_val;
00262     }
00263   else
00264     {
00265     return eT(0);
00266     }
00267   }

template<typename T >
T running_stat_aux::var ( const running_stat< std::complex< T > > &  x,
const u32  norm_type = 0 
) [inline, static, inherited]

variance (version for complex numbers)

Definition at line 275 of file running_stat_meat.hpp.

References norm().

00276   {
00277   arma_extra_debug_sigprint();
00278 
00279   if(x.N > T(1))
00280     {
00281     const T norm_val = (norm_type == 0) ? (x.N-T(1)) : x.N;
00282     const T var_val  = (x.acc2 - std::norm(x.acc1)/x.N) / norm_val;
00283     return var_val;
00284     }
00285   else
00286     {
00287     return T(0);
00288     }
00289   }