libsequence  1.9.5
descriptiveStats.hpp
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5 Remove the brackets to email me.
6 
7 This file is part of libsequence.
8 
9 libsequence is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 libsequence is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef __DESCRIPTIVE_STATS_H__
25 #define __DESCRIPTIVE_STATS_H__
26 
27 #include <type_traits>
28 #include <utility>
29 
38 namespace Sequence
39 {
40 
47  template<typename iterator>
48  double mean(iterator beg, iterator end);
49 
56  template<typename iterator>
57  double variance(iterator beg, iterator end);
58 
66  template<typename ForwardIterator>
67  std::pair<double,double> meanAndVar(ForwardIterator beg,
68  ForwardIterator end);
69 
94  template< typename T >
95  class Sums
96  {
97  public:
98  //T must be convertible to floating_type via a typecast
99  static_assert( std::is_convertible<T,double>::value,
100  "T must be convertible to double");
101  private:
102  T __sum,__sumsq;
103  unsigned __n;
104  public:
105  Sums();
106  Sums<T> & operator+=(const T &);
107  Sums<T> & operator+=(const Sums<T> &);
108  const T & sum() const;
109  const T & sumSquares() const;
110  double mean() const;
111  double variance() const;
112  };
113 
114  template<typename T>
115  const Sums<T> operator+(const Sums<T> & lhs,const Sums<T> & rhs);
116 
117  template<typename T>
118  const Sums<T> operator+(const Sums<T> & lhs,const T & rhs);
119 
120 }//namespace Sequence
121 #include <Sequence/bits/descriptiveStats.tcc>
122 #endif
std::pair< double, double > meanAndVar(ForwardIterator beg, ForwardIterator end)
The namespace in which this library resides.
double mean(iterator beg, iterator end)
double variance(iterator beg, iterator end)
col_view_iterator< POINTER > operator+(col_view_iterator< POINTER > i, typename col_view_iterator< POINTER >::difference_type d)