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 inline running_stat_vec(const running_stat_vec& in_rsv); 00037 00038 inline const running_stat_vec& operator=(const running_stat_vec& in_rsv); 00039 00040 template<typename T1> arma_hot inline void operator() (const Base< T, T1>& X); 00041 template<typename T1> arma_hot inline void operator() (const Base< std::complex<T>, T1>& X); 00042 00043 inline void reset(); 00044 00045 inline const Mat<eT>& mean() const; 00046 00047 inline const Mat< T>& var (const u32 norm_type = 0); 00048 inline Mat< T> stddev(const u32 norm_type = 0) const; 00049 inline const Mat<eT>& cov (const u32 norm_type = 0); 00050 00051 inline const Mat<eT>& min() const; 00052 inline const Mat<eT>& max() const; 00053 00054 // 00055 // 00056 00057 private: 00058 00059 const bool calc_cov; 00060 00061 arma_aligned arma_counter<T> counter; 00062 00063 arma_aligned Mat<eT> r_mean; 00064 arma_aligned Mat< T> r_var; 00065 arma_aligned Mat<eT> r_cov; 00066 00067 arma_aligned Mat<eT> min_val; 00068 arma_aligned Mat<eT> max_val; 00069 00070 arma_aligned Mat< T> min_val_norm; 00071 arma_aligned Mat< T> max_val_norm; 00072 00073 arma_aligned Mat< T> r_var_dummy; 00074 arma_aligned Mat<eT> r_cov_dummy; 00075 00076 arma_aligned Mat<eT> tmp1; 00077 arma_aligned Mat<eT> tmp2; 00078 00079 friend class running_stat_vec_aux; 00080 }; 00081 00082 00083 00084 class running_stat_vec_aux 00085 { 00086 public: 00087 00088 template<typename eT> 00089 inline static void update_stats(running_stat_vec< eT >& x, const Mat<eT>& sample); 00090 00091 template<typename T> 00092 inline static void update_stats(running_stat_vec< std::complex<T> >& x, const Mat< T>& sample); 00093 00094 template<typename T> 00095 inline static void update_stats(running_stat_vec< std::complex<T> >& x, const Mat< std::complex<T> >& sample); 00096 00097 // 00098 00099 template<typename eT> 00100 inline static Mat<eT> var(const running_stat_vec< eT >& x, const u32 norm_type = 0); 00101 00102 template<typename T> 00103 inline static Mat< T> var(const running_stat_vec< std::complex<T> >& x, const u32 norm_type = 0); 00104 00105 // 00106 00107 template<typename eT> 00108 inline static Mat< eT > cov(const running_stat_vec< eT >& x, const u32 norm_type = 0); 00109 00110 template<typename T> 00111 inline static Mat< std::complex<T> > cov(const running_stat_vec< std::complex<T> >& x, const u32 norm_type = 0); 00112 }; 00113 00114 00115 00116 //! @}