1 | #ifndef _theplu_yat_regression_local_ |
---|
2 | #define _theplu_yat_regression_local_ |
---|
3 | |
---|
4 | // $Id: Local.h 1392 2008-07-28 19:35:30Z peter $ |
---|
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 2 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 this program; if not, write to the Free Software |
---|
25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
26 | 02111-1307, USA. |
---|
27 | */ |
---|
28 | |
---|
29 | #include "yat/utility/Vector.h" |
---|
30 | |
---|
31 | #include <iostream> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace regression { |
---|
36 | |
---|
37 | class Kernel; |
---|
38 | class OneDimensionalWeighted; |
---|
39 | |
---|
40 | /// |
---|
41 | /// @brief Class for Locally weighted regression. |
---|
42 | /// |
---|
43 | /// Locally weighted regression is an algorithm for learning |
---|
44 | /// continuous non-linear mappings in a non-parametric manner. In |
---|
45 | /// locally weighted regression, points are weighted by proximity to |
---|
46 | /// the current x in question using a Kernel. A weighted regression |
---|
47 | /// is then computed using the weighted points and a specific |
---|
48 | /// Regression method. This procedure is repeated, which results in |
---|
49 | /// a pointwise approximation of the underlying (unknown) function. |
---|
50 | /// |
---|
51 | class Local |
---|
52 | { |
---|
53 | |
---|
54 | public: |
---|
55 | /// |
---|
56 | /// @brief Constructor taking type of \a regressor, |
---|
57 | /// type of \a kernel. |
---|
58 | /// |
---|
59 | Local(OneDimensionalWeighted& r, Kernel& k); |
---|
60 | |
---|
61 | /// |
---|
62 | /// @brief The destructor |
---|
63 | /// |
---|
64 | virtual ~Local(void); |
---|
65 | |
---|
66 | /// |
---|
67 | /// adding a data point |
---|
68 | /// |
---|
69 | void add(const double x, const double y); |
---|
70 | |
---|
71 | /// |
---|
72 | /// @param nof_points Number of points used in each fit |
---|
73 | /// @param step_size Size of step between each fit |
---|
74 | /// |
---|
75 | void fit(const size_t step_size, const size_t nof_points); |
---|
76 | |
---|
77 | /// |
---|
78 | /// @return x-values where fitting was performed. |
---|
79 | /// |
---|
80 | const utility::Vector& x(void) const; |
---|
81 | |
---|
82 | /// |
---|
83 | /// Function returning predicted values |
---|
84 | /// |
---|
85 | const utility::Vector& y_predicted(void) const; |
---|
86 | |
---|
87 | /// |
---|
88 | /// Function returning error of predictions |
---|
89 | /// |
---|
90 | const utility::Vector& y_err(void) const; |
---|
91 | |
---|
92 | private: |
---|
93 | /// |
---|
94 | /// Copy Constructor. (Not implemented) |
---|
95 | /// |
---|
96 | Local(const Local&); |
---|
97 | |
---|
98 | std::vector<std::pair<double, double> > data_; |
---|
99 | Kernel* kernel_; |
---|
100 | OneDimensionalWeighted* regressor_; |
---|
101 | utility::Vector x_; |
---|
102 | utility::Vector y_predicted_; |
---|
103 | utility::Vector y_err_; |
---|
104 | }; |
---|
105 | |
---|
106 | /// |
---|
107 | /// The output operator for the Regression::Local class. |
---|
108 | /// |
---|
109 | std::ostream& operator<<(std::ostream&, const Local& ); |
---|
110 | |
---|
111 | }}} // of namespaces regression, yat, and theplu |
---|
112 | |
---|
113 | #endif |
---|