1 | #ifndef _theplu_yat_regression_local_ |
---|
2 | #define _theplu_yat_regression_local_ |
---|
3 | |
---|
4 | // $Id: Local.h 1487 2008-09-10 08:41:36Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
9 | Copyright (C) 2008 Peter Johansson |
---|
10 | |
---|
11 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
12 | |
---|
13 | The yat library is free software; you can redistribute it and/or |
---|
14 | modify it under the terms of the GNU General Public License as |
---|
15 | published by the Free Software Foundation; either version 3 of the |
---|
16 | License, or (at your option) any later version. |
---|
17 | |
---|
18 | The yat library is distributed in the hope that it will be useful, |
---|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
21 | General Public License for more details. |
---|
22 | |
---|
23 | You should have received a copy of the GNU General Public License |
---|
24 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
25 | */ |
---|
26 | |
---|
27 | #include "yat/utility/Vector.h" |
---|
28 | |
---|
29 | #include <iostream> |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace regression { |
---|
34 | |
---|
35 | class Kernel; |
---|
36 | class OneDimensionalWeighted; |
---|
37 | |
---|
38 | /// |
---|
39 | /// @brief Class for Locally weighted regression. |
---|
40 | /// |
---|
41 | /// Locally weighted regression is an algorithm for learning |
---|
42 | /// continuous non-linear mappings in a non-parametric manner. In |
---|
43 | /// locally weighted regression, points are weighted by proximity to |
---|
44 | /// the current x in question using a Kernel. A weighted regression |
---|
45 | /// is then computed using the weighted points and a specific |
---|
46 | /// Regression method. This procedure is repeated, which results in |
---|
47 | /// a pointwise approximation of the underlying (unknown) function. |
---|
48 | /// |
---|
49 | class Local |
---|
50 | { |
---|
51 | |
---|
52 | public: |
---|
53 | /// |
---|
54 | /// @brief Constructor taking type of \a regressor, |
---|
55 | /// type of \a kernel. |
---|
56 | /// |
---|
57 | Local(OneDimensionalWeighted& r, Kernel& k); |
---|
58 | |
---|
59 | /// |
---|
60 | /// @brief The destructor |
---|
61 | /// |
---|
62 | virtual ~Local(void); |
---|
63 | |
---|
64 | /// |
---|
65 | /// adding a data point |
---|
66 | /// |
---|
67 | void add(const double x, const double y); |
---|
68 | |
---|
69 | /// |
---|
70 | /// @param step_size Size of step between each fit |
---|
71 | /// @param nof_points Number of points used in each fit |
---|
72 | /// |
---|
73 | /// \throw std::runtime_error if step_size is 0, nof_points is |
---|
74 | /// less than 3, or step_size is larger than number of added data |
---|
75 | /// points. |
---|
76 | void fit(const size_t step_size, const size_t nof_points); |
---|
77 | |
---|
78 | /** |
---|
79 | \brief Set everything to zero |
---|
80 | |
---|
81 | \since New in yat 0.5 |
---|
82 | */ |
---|
83 | void reset(void); |
---|
84 | |
---|
85 | /// |
---|
86 | /// @return x-values where fitting was performed. |
---|
87 | /// |
---|
88 | const utility::Vector& x(void) const; |
---|
89 | |
---|
90 | /// |
---|
91 | /// Function returning predicted values |
---|
92 | /// |
---|
93 | const utility::Vector& y_predicted(void) const; |
---|
94 | |
---|
95 | /// |
---|
96 | /// Function returning error of predictions |
---|
97 | /// |
---|
98 | const utility::Vector& y_err(void) const; |
---|
99 | |
---|
100 | private: |
---|
101 | /// |
---|
102 | /// Copy Constructor. (Not implemented) |
---|
103 | /// |
---|
104 | Local(const Local&); |
---|
105 | |
---|
106 | std::vector<std::pair<double, double> > data_; |
---|
107 | Kernel* kernel_; |
---|
108 | OneDimensionalWeighted* regressor_; |
---|
109 | utility::Vector x_; |
---|
110 | utility::Vector y_predicted_; |
---|
111 | utility::Vector y_err_; |
---|
112 | }; |
---|
113 | |
---|
114 | /// |
---|
115 | /// The output operator for the Regression::Local class. |
---|
116 | /// |
---|
117 | std::ostream& operator<<(std::ostream&, const Local& ); |
---|
118 | |
---|
119 | }}} // of namespaces regression, yat, and theplu |
---|
120 | |
---|
121 | #endif |
---|