source: trunk/yat/statistics/Smoother.h @ 1311

Last change on this file since 1311 was 1311, checked in by Peter, 13 years ago

fixed missing documentation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1#ifndef _theplu_yat_statistics_smoother_
2#define _theplu_yat_statistics_smoother_
3
4// $Id: Smoother.h 1311 2008-05-16 13:58:52Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://trac.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27
28#include "yat/utility/iterator_traits.h"
29
30#include <vector>
31
32namespace theplu {
33namespace yat {
34  namespace regression { 
35    class Kernel; 
36  }
37namespace statistics {
38
39  /**
40     @brief Estimating a distribution in a smooth fashion
41  */
42  class Smoother
43  {
44  public:
45    /**
46       Constructor taking vector describing for which values
47       distribution should be estimated.
48
49       \note if \a values are not sorted the behavior is undefined
50     */
51    Smoother(const regression::Kernel&, double width, 
52             const std::vector<double>& values);
53
54    /**
55       Constructor creating observation points equally distributed
56       between \a xmin and \a xmax.
57
58       \param kernel doing the smoothing
59       \param width
60       \param xmin smallest observation point
61       \param xmax largest observation point
62       \param n number of observation points
63     */
64    Smoother(const regression::Kernel& kernel, double width, 
65             double xmin, double xmax, size_t n);
66
67    /**
68       \brief Add a data point.
69    */
70    void add(double x, double weight=1.0);
71
72    /**
73       \brief estimated values
74     */
75    const std::vector<double>& density(void) const;
76
77    /**
78       \brief reset density to zero
79     */
80    void reset(void);
81
82    /**
83       \brief values in which distribution is estimated
84     */
85    const std::vector<double>& value(void) const;
86
87  private:
88    std::vector<double> density_;
89    const regression::Kernel& kernel_;
90    double width_;
91    std::vector<double> x_;
92  };
93
94  /**
95     Add a range [first, last) of values to Smoother.
96   */
97  template<typename ForwardIterator>
98  void add(Smoother& h, 
99           ForwardIterator first, ForwardIterator last)
100  {
101    while (first!=last) {
102      h.add(utility::iterator_traits<ForwardIterator>().data(),
103            utility::iterator_traits<ForwardIterator>().weight());
104      ++first;
105    }
106  }
107
108  /**
109     The Smoother output operator
110  */
111  std::ostream& operator<<(std::ostream& s,const Smoother&);
112
113}}} // of namespace statistics, yat, and theplu
114
115#endif
Note: See TracBrowser for help on using the repository browser.