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

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

closes #554 - added function rescale in Smoother

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1#ifndef _theplu_yat_statistics_smoother_
2#define _theplu_yat_statistics_smoother_
3
4// $Id: Smoother.h 2039 2009-08-26 14:42:57Z 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       multiply each value with \a factor
80       
81       \since New in yat 0.6
82     */
83    void rescale(double factor);
84
85    /**
86       \brief reset density to zero
87     */
88    void reset(void);
89
90    /**
91       \brief values in which distribution is estimated
92     */
93    const std::vector<double>& value(void) const;
94
95  private:
96    std::vector<double> density_;
97    const regression::Kernel& kernel_;
98    double width_;
99    std::vector<double> x_;
100  };
101
102  /**
103     Add a range [first, last) of values to Smoother.
104
105     \relates Smoother
106   */
107  template<typename ForwardIterator>
108  void add(Smoother& h, 
109           ForwardIterator first, ForwardIterator last)
110  {
111    while (first!=last) {
112      h.add(utility::iterator_traits<ForwardIterator>().data(),
113            utility::iterator_traits<ForwardIterator>().weight());
114      ++first;
115    }
116  }
117
118  /**
119     The Smoother output operator
120
121     \relates Smoother
122  */
123  std::ostream& operator<<(std::ostream& s,const Smoother&);
124
125}}} // of namespace statistics, yat, and theplu
126
127#endif
Note: See TracBrowser for help on using the repository browser.