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_vec 00018 //! @{ 00019 00020 00021 00022 //! Class for keeping statistics of a continuously sampled process / signal. 00023 //! Useful if the storage of individual samples is not necessary or desired. 00024 //! Also useful if the number of samples is not known beforehand or exceeds 00025 //! available memory. 00026 template<typename eT> 00027 class running_stat_vec 00028 { 00029 public: 00030 00031 typedef typename get_pod_type<eT>::result T; 00032 00033 inline ~running_stat_vec(); 00034 inline running_stat_vec(const bool in_calc_cov = false); 00035 00036 template<typename T1> inline void operator() (const Base< T, T1>& X); 00037 template<typename T1> inline void operator() (const Base< std::complex<T>, T1>& X); 00038 00039 inline void reset(); 00040 00041 inline Mat<eT> mean() const; 00042 00043 inline Mat< T> var (const u32 norm_type = 0) const; 00044 inline Mat< T> stddev(const u32 norm_type = 0) const; 00045 inline Mat<eT> cov (const u32 norm_type = 0) const; 00046 00047 inline Mat<eT> min() const; 00048 inline Mat<eT> max() const; 00049 00050 // 00051 // 00052 00053 private: 00054 00055 const bool calc_cov; 00056 00057 arma_aligned arma_counter<T> counter; 00058 00059 arma_aligned Mat<eT> r_mean; 00060 arma_aligned Mat< T> r_var; 00061 arma_aligned Mat<eT> r_cov; 00062 00063 arma_aligned Mat<eT> min_val; 00064 arma_aligned Mat<eT> max_val; 00065 00066 arma_aligned Mat< T> min_val_norm; 00067 arma_aligned Mat< T> max_val_norm; 00068 00069 friend class running_stat_vec_aux; 00070 }; 00071 00072 00073 00074 class running_stat_vec_aux 00075 { 00076 public: 00077 00078 template<typename eT> 00079 inline static void update_stats(running_stat_vec< eT >& x, const Mat<eT>& sample); 00080 00081 template<typename T> 00082 inline static void update_stats(running_stat_vec< std::complex<T> >& x, const Mat< T>& sample); 00083 00084 template<typename T> 00085 inline static void update_stats(running_stat_vec< std::complex<T> >& x, const Mat< std::complex<T> >& sample); 00086 00087 // 00088 00089 template<typename eT> 00090 inline static Mat<eT> var(const running_stat_vec< eT >& x, const u32 norm_type = 0); 00091 00092 template<typename T> 00093 inline static Mat< T> var(const running_stat_vec< std::complex<T> >& x, const u32 norm_type = 0); 00094 00095 // 00096 00097 template<typename eT> 00098 inline static Mat< eT > cov(const running_stat_vec< eT >& x, const u32 norm_type = 0); 00099 00100 template<typename T> 00101 inline static Mat< std::complex<T> > cov(const running_stat_vec< std::complex<T> >& x, const u32 norm_type = 0); 00102 }; 00103 00104 00105 00106 //! @}