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