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

Last change on this file since 1886 was 1886, checked in by Peter, 12 years ago

refs #512. added relates tag in namespace statistics.

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