1 | #ifndef _theplu_yat_statistics_smoother_ |
---|
2 | #define _theplu_yat_statistics_smoother_ |
---|
3 | |
---|
4 | // $Id: Smoother.h 1310 2008-05-15 19:12:17Z 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 | |
---|
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 | 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 | */ |
---|
74 | const std::vector<double>& density(void) const; |
---|
75 | |
---|
76 | /** |
---|
77 | */ |
---|
78 | void reset(void); |
---|
79 | |
---|
80 | /** |
---|
81 | */ |
---|
82 | const std::vector<double>& value(void) const; |
---|
83 | |
---|
84 | private: |
---|
85 | std::vector<double> density_; |
---|
86 | const regression::Kernel& kernel_; |
---|
87 | double width_; |
---|
88 | std::vector<double> x_; |
---|
89 | }; |
---|
90 | |
---|
91 | /** |
---|
92 | Add a range [first, last) of values to Smoother. |
---|
93 | */ |
---|
94 | template<typename ForwardIterator> |
---|
95 | void add(Smoother& h, |
---|
96 | ForwardIterator first, ForwardIterator last) |
---|
97 | { |
---|
98 | while (first!=last) { |
---|
99 | h.add(utility::iterator_traits<ForwardIterator>().data(), |
---|
100 | utility::iterator_traits<ForwardIterator>().weight()); |
---|
101 | ++first; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | The Smoother output operator |
---|
107 | */ |
---|
108 | std::ostream& operator<<(std::ostream& s,const Smoother&); |
---|
109 | |
---|
110 | }}} // of namespace statistics, yat, and theplu |
---|
111 | |
---|
112 | #endif |
---|