1 | #ifndef _theplu_yat_statistics_smoother_ |
---|
2 | #define _theplu_yat_statistics_smoother_ |
---|
3 | |
---|
4 | // $Id: Smoother.h 1486 2008-09-09 21:17:19Z 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 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 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace regression { |
---|
35 | class Kernel; |
---|
36 | } |
---|
37 | namespace statistics { |
---|
38 | |
---|
39 | /** |
---|
40 | @brief Estimating a distribution in a smooth fashion |
---|
41 | |
---|
42 | \since New in yat 0.5 |
---|
43 | */ |
---|
44 | class Smoother |
---|
45 | { |
---|
46 | public: |
---|
47 | /** |
---|
48 | Constructor taking vector describing for which values |
---|
49 | distribution should be estimated. |
---|
50 | |
---|
51 | \note if \a values are not sorted the behavior is undefined |
---|
52 | */ |
---|
53 | Smoother(const regression::Kernel&, double width, |
---|
54 | const std::vector<double>& values); |
---|
55 | |
---|
56 | /** |
---|
57 | Constructor creating observation points equally distributed |
---|
58 | between \a xmin and \a xmax. |
---|
59 | |
---|
60 | \param kernel doing the smoothing |
---|
61 | \param width |
---|
62 | \param xmin smallest observation point |
---|
63 | \param xmax largest observation point |
---|
64 | \param n number of observation points |
---|
65 | */ |
---|
66 | Smoother(const regression::Kernel& kernel, double width, |
---|
67 | double xmin, double xmax, size_t n); |
---|
68 | |
---|
69 | /** |
---|
70 | \brief Add a data point. |
---|
71 | */ |
---|
72 | void add(double x, double weight=1.0); |
---|
73 | |
---|
74 | /** |
---|
75 | \brief estimated values |
---|
76 | */ |
---|
77 | const std::vector<double>& density(void) const; |
---|
78 | |
---|
79 | /** |
---|
80 | \brief reset density to zero |
---|
81 | */ |
---|
82 | void reset(void); |
---|
83 | |
---|
84 | /** |
---|
85 | \brief values in which distribution is estimated |
---|
86 | */ |
---|
87 | const std::vector<double>& value(void) const; |
---|
88 | |
---|
89 | private: |
---|
90 | std::vector<double> density_; |
---|
91 | const regression::Kernel& kernel_; |
---|
92 | double width_; |
---|
93 | std::vector<double> x_; |
---|
94 | }; |
---|
95 | |
---|
96 | /** |
---|
97 | Add a range [first, last) of values to Smoother. |
---|
98 | */ |
---|
99 | template<typename ForwardIterator> |
---|
100 | void add(Smoother& h, |
---|
101 | ForwardIterator first, ForwardIterator last) |
---|
102 | { |
---|
103 | while (first!=last) { |
---|
104 | h.add(utility::iterator_traits<ForwardIterator>().data(), |
---|
105 | utility::iterator_traits<ForwardIterator>().weight()); |
---|
106 | ++first; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | The Smoother output operator |
---|
112 | */ |
---|
113 | std::ostream& operator<<(std::ostream& s,const Smoother&); |
---|
114 | |
---|
115 | }}} // of namespace statistics, yat, and theplu |
---|
116 | |
---|
117 | #endif |
---|