yat  0.8.3pre
Histogram.h
00001 #ifndef _theplu_yat_statistics_histogram_
00002 #define _theplu_yat_statistics_histogram_
00003 
00004 // $Id: Histogram.h 2333 2010-10-15 00:44:23Z peter $
00005 
00006 /*
00007   Copyright (C) 2004 Jari Häkkinen
00008   Copyright (C) 2005 Jari Häkkinen, Peter Johansson
00009   Copyright (C) 2006 Jari Häkkinen
00010   Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
00011   Copyright (C) 2009, 2010 Peter Johansson
00012 
00013   This file is part of the yat library, http://dev.thep.lu.se/yat
00014 
00015   The yat library is free software; you can redistribute it and/or
00016   modify it under the terms of the GNU General Public License as
00017   published by the Free Software Foundation; either version 3 of the
00018   License, or (at your option) any later version.
00019 
00020   The yat library is distributed in the hope that it will be useful,
00021   but WITHOUT ANY WARRANTY; without even the implied warranty of
00022   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00023   General Public License for more details.
00024 
00025   You should have received a copy of the GNU General Public License
00026   along with yat. If not, see <http://www.gnu.org/licenses/>.
00027 */
00028 
00029 #include "AveragerWeighted.h"
00030 #include "yat/utility/concept_check.h"
00031 #include "yat/utility/iterator_traits.h"
00032 
00033 #include <boost/concept_check.hpp>
00034 
00035 #include <iosfwd>
00036 #include <string>
00037 #include <vector>
00038 
00039 namespace theplu {
00040 namespace yat {
00041 namespace statistics {
00042 
00052   class Histogram
00053   {
00054   public:
00055 
00059     Histogram(void);
00060 
00074     Histogram(std::istream&);
00075 
00079     Histogram(const Histogram&);
00080 
00085     Histogram(const double xmin, const double xmax, const size_t n);
00086 
00087     virtual ~Histogram(void);
00088 
00102     int add(const double x,const double weight=1.0);
00103 
00112     const AveragerWeighted& averager_all(void) const;
00113 
00123     const AveragerWeighted& averager_histogram(void) const;
00124 
00128     size_t nof_bins(void) const;
00129 
00156     void normalize(bool choice = true);
00157 
00164     double observation_value(const size_t k) const;
00165 
00171     void rescale(double factor);
00172 
00177     void reset(void);
00178 
00182     double spacing(void) const;
00183 
00189     double xmax(void) const;
00190 
00196     double xmin(void) const;
00197 
00201     double operator[](size_t k) const;
00202 
00206     const Histogram& operator=(const Histogram&);
00207 
00216     const Histogram& operator+=(const Histogram& rhs);
00217 
00218   private:
00219     // Returns zero if outside boundaries
00220     size_t bin(double d);
00221 
00222     std::vector<double> histogram_;
00223     double xmax_;
00224     double xmin_;
00225     statistics::AveragerWeighted sum_all_;      // average of all data
00226     statistics::AveragerWeighted sum_histogram_;// average of data in histogram
00227   };
00228 
00236   template<typename ForwardIterator>
00237   void add(Histogram& h, 
00238            ForwardIterator first, ForwardIterator last)
00239   {
00240     BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>));
00241     BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<ForwardIterator>));
00242     utility::iterator_traits<ForwardIterator> traits;
00243     while (first!=last) {
00244       h.add(traits.data(first), traits.weight(first));
00245       ++first;
00246     }
00247   }
00248 
00254   std::ostream& operator<<(std::ostream& s,const Histogram&);
00255 
00256 }}} // of namespace statistics, yat, and theplu
00257 
00258 #endif

Generated on Thu Dec 20 2012 03:12:58 for yat by  doxygen 1.8.0-20120409