running_stat_bones.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. //! \addtogroup running_stat
  16. //! @{
  17. template<typename eT>
  18. class arma_counter
  19. {
  20. public:
  21. inline ~arma_counter();
  22. inline arma_counter();
  23. inline const arma_counter& operator++();
  24. inline void operator++(int);
  25. inline void reset();
  26. inline eT value() const;
  27. inline eT value_plus_1() const;
  28. inline eT value_minus_1() const;
  29. private:
  30. arma_aligned eT d_count;
  31. arma_aligned uword i_count;
  32. };
  33. //! Class for keeping statistics of a continuously sampled process / signal.
  34. //! Useful if the storage of individual samples is not necessary or desired.
  35. //! Also useful if the number of samples is not known beforehand or exceeds
  36. //! available memory.
  37. template<typename eT>
  38. class running_stat
  39. {
  40. public:
  41. typedef typename get_pod_type<eT>::result T;
  42. inline ~running_stat();
  43. inline running_stat();
  44. inline void operator() (const T sample);
  45. inline void operator() (const std::complex<T>& sample);
  46. inline void reset();
  47. inline eT mean() const;
  48. inline T var (const uword norm_type = 0) const;
  49. inline T stddev(const uword norm_type = 0) const;
  50. inline eT min() const;
  51. inline eT max() const;
  52. inline eT range() const;
  53. inline T count() const;
  54. //
  55. //
  56. private:
  57. arma_aligned arma_counter<T> counter;
  58. arma_aligned eT r_mean;
  59. arma_aligned T r_var;
  60. arma_aligned eT min_val;
  61. arma_aligned eT max_val;
  62. arma_aligned T min_val_norm;
  63. arma_aligned T max_val_norm;
  64. friend class running_stat_aux;
  65. };
  66. class running_stat_aux
  67. {
  68. public:
  69. template<typename eT>
  70. inline static void update_stats(running_stat<eT>& x, const eT sample, const typename arma_not_cx<eT>::result* junk = 0);
  71. template<typename eT>
  72. inline static void update_stats(running_stat<eT>& x, const std::complex<eT>& sample, const typename arma_not_cx<eT>::result* junk = 0);
  73. template<typename eT>
  74. inline static void update_stats(running_stat<eT>& x, const typename eT::value_type sample, const typename arma_cx_only<eT>::result* junk = 0);
  75. template<typename eT>
  76. inline static void update_stats(running_stat<eT>& x, const eT& sample, const typename arma_cx_only<eT>::result* junk = 0);
  77. };
  78. //! @}