Classes | Functions

Running_stat

//! More...

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::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)

Detailed Description

//!


Function Documentation

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

Definition at line 24 of file running_stat_meat.hpp.

  {
  arma_extra_debug_sigprint_this(this);
  }

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

Definition at line 33 of file running_stat_meat.hpp.

  : d_count( eT(0))
  , i_count(u32(0))
  {
  arma_extra_debug_sigprint_this(this);
  }

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

Definition at line 45 of file running_stat_meat.hpp.

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

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

  {
  const u32 max_val = 0xffffffff;
  
  if(i_count < max_val)
    {
    i_count++;
    }
  else
    {
    d_count += eT(max_val);
    i_count =  1;
    }
  
  return *this;
  }

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

Definition at line 67 of file running_stat_meat.hpp.

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

  {
  operator++();
  }

template<typename eT >
void arma_counter< eT >::reset (  )  [inline, inherited]
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 99 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().

  {
  const u32 max_val = 0xffffffff;
  
  if(i_count < max_val)
    {
    return d_count + eT(i_count + 1);
    }
  else
    {
    return d_count + eT(max_val) + eT(1);
    }
  }

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

Definition at line 139 of file running_stat_meat.hpp.

  {
  arma_extra_debug_sigprint_this(this);
  }

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

Definition at line 147 of file running_stat_meat.hpp.

  : r_mean      (                          eT(0))
  , r_var       (typename running_stat<eT>::T(0))
  , min_val     (                          eT(0))
  , max_val     (                          eT(0))
  , min_val_norm(typename running_stat<eT>::T(0))
  , max_val_norm(typename running_stat<eT>::T(0))
  {
  arma_extra_debug_sigprint_this(this);
  }

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

mean or average value

Definition at line 220 of file running_stat_meat.hpp.

References running_stat< eT >::r_mean.

  {
  arma_extra_debug_sigprint();
  
  return r_mean;
  }

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

variance

Definition at line 234 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().

  {
  arma_extra_debug_sigprint();
  
  const T N = counter.value();
  
  if(N > T(1))
    {
    if(norm_type == 0)
      {
      return r_var;
      }
    else
      {
      const T N_minus_1 = counter.value_minus_1();
      return (N_minus_1/N) * r_var;
      }
    }
  else
    {
    return T(0);
    }
  }

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

standard deviation

Definition at line 265 of file running_stat_meat.hpp.

References sqrt().

  {
  arma_extra_debug_sigprint();

  return std::sqrt( (*this).var(norm_type) );
  }

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

minimum value

Definition at line 279 of file running_stat_meat.hpp.

References running_stat< eT >::min_val.

  {
  arma_extra_debug_sigprint();
  
  return min_val;
  }

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

maximum value

Definition at line 293 of file running_stat_meat.hpp.

References running_stat< eT >::max_val.

  {
  arma_extra_debug_sigprint();

  return max_val;
  }

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 307 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_aux::update_stats().

  {
  arma_extra_debug_sigprint();
  
  typedef typename running_stat<eT>::T T;
  
  const T N = x.counter.value();
  
  if(N > T(0))
    {
    if(sample < x.min_val)
      {
      x.min_val = sample;
      }
    
    if(sample > x.max_val)
      {
      x.max_val = sample;
      }
    
    const T  N_plus_1   = x.counter.value_plus_1();
    const T  N_minus_1  = x.counter.value_minus_1();
    
    // note: variance has to be updated before the mean
    
    const eT tmp = sample - x.r_mean;
    
    x.r_var  = N_minus_1/N * x.r_var + (tmp*tmp)/N_plus_1;
    
    x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1;
    //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1;
    //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1;
    }
  else
    {
    x.r_mean  = sample;
    x.min_val = sample;
    x.max_val = sample;
    
    // r_var is initialised to zero
    // in the constructor and reset()
    }
  
  x.counter++;
  }

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

References running_stat_aux::update_stats().

  {
  arma_extra_debug_sigprint();

  running_stat_aux::update_stats(x, std::complex<T>(sample));
  }

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

References norm().

  {
  arma_extra_debug_sigprint();
  
  typedef typename std::complex<T> eT;
  
  const T sample_norm = std::norm(sample);
  const T N           = x.counter.value();
  
  if(N > T(0))
    {
    if(sample_norm < x.min_val_norm)
      {
      x.min_val_norm = sample_norm;
      x.min_val      = sample;
      }
    
    if(sample_norm > x.max_val_norm)
      {
      x.max_val_norm = sample_norm;
      x.max_val      = sample;
      }
    
    const T  N_plus_1   = x.counter.value_plus_1();
    const T  N_minus_1  = x.counter.value_minus_1();
    
    x.r_var = N_minus_1/N * x.r_var + std::norm(sample - x.r_mean)/N_plus_1;
    
    x.r_mean = x.r_mean + (sample - x.r_mean)/N_plus_1;
    //x.r_mean = (N/N_plus_1)*x.r_mean + sample/N_plus_1;
    //x.r_mean = (x.r_mean + sample/N) * N/N_plus_1;
    }
  else
    {
    x.r_mean       = sample;
    x.min_val      = sample;
    x.max_val      = sample;
    x.min_val_norm = sample_norm;
    x.max_val_norm = sample_norm;
    
    // r_var is initialised to zero
    // in the constructor and reset()
    }
  
  x.counter++;
  }