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

Last change on this file since 1701 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • 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 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25
26#include "yat/utility/iterator_traits.h"
27
28#include <vector>
29
30namespace theplu {
31namespace yat {
32  namespace regression { 
33    class Kernel; 
34  }
35namespace statistics {
36
37  /**
38     @brief Estimating a distribution in a smooth fashion
39
40     \since New in yat 0.5
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.