Mercurial > hg > vamp-build-and-test
annotate DEPENDENCIES/generic/include/boost/math/tools/stats.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
rev | line source |
---|---|
Chris@16 | 1 // (C) Copyright John Maddock 2005-2006. |
Chris@16 | 2 // Use, modification and distribution are subject to the |
Chris@16 | 3 // Boost Software License, Version 1.0. (See accompanying file |
Chris@16 | 4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
Chris@16 | 5 |
Chris@16 | 6 #ifndef BOOST_MATH_TOOLS_STATS_INCLUDED |
Chris@16 | 7 #define BOOST_MATH_TOOLS_STATS_INCLUDED |
Chris@16 | 8 |
Chris@16 | 9 #ifdef _MSC_VER |
Chris@16 | 10 #pragma once |
Chris@16 | 11 #endif |
Chris@16 | 12 |
Chris@16 | 13 #include <boost/config/no_tr1/cmath.hpp> |
Chris@16 | 14 #include <boost/cstdint.hpp> |
Chris@16 | 15 #include <boost/math/tools/precision.hpp> |
Chris@16 | 16 |
Chris@16 | 17 namespace boost{ namespace math{ namespace tools{ |
Chris@16 | 18 |
Chris@16 | 19 template <class T> |
Chris@16 | 20 class stats |
Chris@16 | 21 { |
Chris@16 | 22 public: |
Chris@16 | 23 stats() |
Chris@16 | 24 : m_min(tools::max_value<T>()), |
Chris@16 | 25 m_max(-tools::max_value<T>()), |
Chris@16 | 26 m_total(0), |
Chris@16 | 27 m_squared_total(0), |
Chris@16 | 28 m_count(0) |
Chris@16 | 29 {} |
Chris@16 | 30 void add(const T& val) |
Chris@16 | 31 { |
Chris@16 | 32 if(val < m_min) |
Chris@16 | 33 m_min = val; |
Chris@16 | 34 if(val > m_max) |
Chris@16 | 35 m_max = val; |
Chris@16 | 36 m_total += val; |
Chris@16 | 37 ++m_count; |
Chris@16 | 38 m_squared_total += val*val; |
Chris@16 | 39 } |
Chris@16 | 40 T min BOOST_PREVENT_MACRO_SUBSTITUTION()const{ return m_min; } |
Chris@16 | 41 T max BOOST_PREVENT_MACRO_SUBSTITUTION()const{ return m_max; } |
Chris@16 | 42 T total()const{ return m_total; } |
Chris@16 | 43 T mean()const{ return m_total / static_cast<T>(m_count); } |
Chris@16 | 44 boost::uintmax_t count()const{ return m_count; } |
Chris@16 | 45 T variance()const |
Chris@16 | 46 { |
Chris@16 | 47 BOOST_MATH_STD_USING |
Chris@16 | 48 |
Chris@16 | 49 T t = m_squared_total - m_total * m_total / m_count; |
Chris@16 | 50 t /= m_count; |
Chris@16 | 51 return t; |
Chris@16 | 52 } |
Chris@16 | 53 T variance1()const |
Chris@16 | 54 { |
Chris@16 | 55 BOOST_MATH_STD_USING |
Chris@16 | 56 |
Chris@16 | 57 T t = m_squared_total - m_total * m_total / m_count; |
Chris@16 | 58 t /= (m_count-1); |
Chris@16 | 59 return t; |
Chris@16 | 60 } |
Chris@16 | 61 T rms()const |
Chris@16 | 62 { |
Chris@16 | 63 BOOST_MATH_STD_USING |
Chris@16 | 64 |
Chris@16 | 65 return sqrt(m_squared_total / static_cast<T>(m_count)); |
Chris@16 | 66 } |
Chris@16 | 67 stats& operator+=(const stats& s) |
Chris@16 | 68 { |
Chris@16 | 69 if(s.m_min < m_min) |
Chris@16 | 70 m_min = s.m_min; |
Chris@16 | 71 if(s.m_max > m_max) |
Chris@16 | 72 m_max = s.m_max; |
Chris@16 | 73 m_total += s.m_total; |
Chris@16 | 74 m_squared_total += s.m_squared_total; |
Chris@16 | 75 m_count += s.m_count; |
Chris@16 | 76 return *this; |
Chris@16 | 77 } |
Chris@16 | 78 private: |
Chris@16 | 79 T m_min, m_max, m_total, m_squared_total; |
Chris@16 | 80 boost::uintmax_t m_count; |
Chris@16 | 81 }; |
Chris@16 | 82 |
Chris@16 | 83 } // namespace tools |
Chris@16 | 84 } // namespace math |
Chris@16 | 85 } // namespace boost |
Chris@16 | 86 |
Chris@16 | 87 #endif |
Chris@16 | 88 |