00001 // Copyright (C) 2010 NICTA and the authors listed below 00002 // http://nicta.com.au 00003 // 00004 // Authors: 00005 // - Conrad Sanderson (conradsand at ieee dot org) 00006 // 00007 // This file is part of the Armadillo C++ library. 00008 // It is provided without any warranty of fitness 00009 // for any purpose. You can redistribute this file 00010 // and/or modify it under the terms of the GNU 00011 // Lesser General Public License (LGPL) as published 00012 // by the Free Software Foundation, either version 3 00013 // of the License or (at your option) any later version. 00014 // (see http://www.opensource.org/licenses for more info) 00015 00016 00017 //! \addtogroup running_stat 00018 //! @{ 00019 00020 00021 00022 template<typename eT> 00023 class arma_counter 00024 { 00025 public: 00026 00027 inline ~arma_counter(); 00028 inline arma_counter(); 00029 00030 inline const arma_counter& operator++(); 00031 inline void operator++(int); 00032 00033 inline void reset(); 00034 inline eT value() const; 00035 inline eT value_plus_1() const; 00036 inline eT value_minus_1() const; 00037 00038 00039 private: 00040 00041 arma_aligned eT d_count; 00042 arma_aligned u32 i_count; 00043 }; 00044 00045 00046 00047 //! Class for keeping statistics of a continuously sampled process / signal. 00048 //! Useful if the storage of individual samples is not necessary or desired. 00049 //! Also useful if the number of samples is not known beforehand or exceeds 00050 //! available memory. 00051 template<typename eT> 00052 class running_stat 00053 { 00054 public: 00055 00056 typedef typename get_pod_type<eT>::result T; 00057 00058 00059 inline ~running_stat(); 00060 inline running_stat(); 00061 00062 inline void operator() (const T sample); 00063 inline void operator() (const std::complex<T>& sample); 00064 00065 inline void reset(); 00066 00067 inline eT mean() const; 00068 00069 inline T var (const u32 norm_type = 0) const; 00070 inline T stddev(const u32 norm_type = 0) const; 00071 00072 inline eT min() const; 00073 inline eT max() const; 00074 00075 // 00076 // 00077 00078 private: 00079 00080 arma_aligned arma_counter<T> counter; 00081 00082 arma_aligned eT r_mean; 00083 arma_aligned T r_var; 00084 00085 arma_aligned eT min_val; 00086 arma_aligned eT max_val; 00087 00088 arma_aligned T min_val_norm; 00089 arma_aligned T max_val_norm; 00090 00091 00092 friend class running_stat_aux; 00093 }; 00094 00095 00096 00097 class running_stat_aux 00098 { 00099 public: 00100 00101 template<typename eT> 00102 inline static void update_stats(running_stat<eT>& x, const eT sample); 00103 00104 template<typename T> 00105 inline static void update_stats(running_stat< std::complex<T> >& x, const T sample); 00106 00107 template<typename T> 00108 inline static void update_stats(running_stat< std::complex<T> >& x, const std::complex<T>& sample); 00109 00110 }; 00111 00112 00113 00114 //! @}