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