681 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_regression_local_ |
681 |
11 Oct 06 |
jari |
2 |
#define _theplu_yat_regression_local_ |
202 |
01 Nov 04 |
peter |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
616 |
31 Aug 06 |
jari |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2004 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010, 2011 Peter Johansson |
202 |
01 Nov 04 |
peter |
12 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
14 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
19 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
24 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
27 |
*/ |
675 |
10 Oct 06 |
jari |
28 |
|
1120 |
21 Feb 08 |
peter |
29 |
#include "yat/utility/Vector.h" |
675 |
10 Oct 06 |
jari |
30 |
|
2532 |
31 Jul 11 |
peter |
31 |
#include <iosfwd> |
202 |
01 Nov 04 |
peter |
32 |
|
202 |
01 Nov 04 |
peter |
33 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
34 |
namespace yat { |
383 |
12 Aug 05 |
jari |
35 |
namespace regression { |
383 |
12 Aug 05 |
jari |
36 |
|
747 |
11 Feb 07 |
peter |
37 |
class Kernel; |
747 |
11 Feb 07 |
peter |
38 |
class OneDimensionalWeighted; |
747 |
11 Feb 07 |
peter |
39 |
|
202 |
01 Nov 04 |
peter |
40 |
/// |
4200 |
19 Aug 22 |
peter |
/// @brief Class for Locally weighted regression. |
202 |
01 Nov 04 |
peter |
42 |
/// |
280 |
20 Apr 05 |
peter |
/// Locally weighted regression is an algorithm for learning |
280 |
20 Apr 05 |
peter |
/// continuous non-linear mappings in a non-parametric manner. In |
280 |
20 Apr 05 |
peter |
/// locally weighted regression, points are weighted by proximity to |
346 |
08 Jun 05 |
peter |
/// the current x in question using a Kernel. A weighted regression |
346 |
08 Jun 05 |
peter |
/// is then computed using the weighted points and a specific |
346 |
08 Jun 05 |
peter |
/// Regression method. This procedure is repeated, which results in |
346 |
08 Jun 05 |
peter |
/// a pointwise approximation of the underlying (unknown) function. |
280 |
20 Apr 05 |
peter |
50 |
/// |
383 |
12 Aug 05 |
jari |
51 |
class Local |
202 |
01 Nov 04 |
peter |
52 |
{ |
4200 |
19 Aug 22 |
peter |
53 |
|
202 |
01 Nov 04 |
peter |
54 |
public: |
202 |
01 Nov 04 |
peter |
55 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief Constructor taking type of \a regressor, |
235 |
21 Feb 05 |
peter |
/// type of \a kernel. |
202 |
01 Nov 04 |
peter |
58 |
/// |
703 |
18 Dec 06 |
jari |
59 |
Local(OneDimensionalWeighted& r, Kernel& k); |
202 |
01 Nov 04 |
peter |
60 |
|
202 |
01 Nov 04 |
peter |
61 |
/// |
4200 |
19 Aug 22 |
peter |
/// @brief The destructor |
202 |
01 Nov 04 |
peter |
63 |
/// |
703 |
18 Dec 06 |
jari |
64 |
virtual ~Local(void); |
206 |
02 Nov 04 |
peter |
65 |
|
221 |
30 Dec 04 |
peter |
66 |
/// |
235 |
21 Feb 05 |
peter |
/// adding a data point |
235 |
21 Feb 05 |
peter |
68 |
/// |
718 |
26 Dec 06 |
jari |
69 |
void add(const double x, const double y); |
235 |
21 Feb 05 |
peter |
70 |
|
235 |
21 Feb 05 |
peter |
71 |
/// |
1437 |
25 Aug 08 |
peter |
/// @param step_size Size of step between each fit |
718 |
26 Dec 06 |
jari |
/// @param nof_points Number of points used in each fit |
221 |
30 Dec 04 |
peter |
74 |
/// |
2210 |
05 Mar 10 |
peter |
/// \throw utility::runtime_error if step_size is 0, nof_points is |
1473 |
03 Sep 08 |
peter |
/// less than 3, or step_size is larger than number of added data |
1473 |
03 Sep 08 |
peter |
/// points. |
718 |
26 Dec 06 |
jari |
78 |
void fit(const size_t step_size, const size_t nof_points); |
221 |
30 Dec 04 |
peter |
79 |
|
1450 |
28 Aug 08 |
peter |
80 |
/** |
1450 |
28 Aug 08 |
peter |
\brief Set everything to zero |
1450 |
28 Aug 08 |
peter |
82 |
|
1450 |
28 Aug 08 |
peter |
\since New in yat 0.5 |
1450 |
28 Aug 08 |
peter |
84 |
*/ |
1450 |
28 Aug 08 |
peter |
85 |
void reset(void); |
1450 |
28 Aug 08 |
peter |
86 |
|
221 |
30 Dec 04 |
peter |
87 |
/// |
718 |
26 Dec 06 |
jari |
/// @return x-values where fitting was performed. |
221 |
30 Dec 04 |
peter |
89 |
/// |
1120 |
21 Feb 08 |
peter |
90 |
const utility::Vector& x(void) const; |
718 |
26 Dec 06 |
jari |
91 |
|
216 |
29 Dec 04 |
peter |
92 |
/// |
718 |
26 Dec 06 |
jari |
/// Function returning predicted values |
216 |
29 Dec 04 |
peter |
94 |
/// |
1120 |
21 Feb 08 |
peter |
95 |
const utility::Vector& y_predicted(void) const; |
235 |
21 Feb 05 |
peter |
96 |
|
430 |
08 Dec 05 |
peter |
97 |
/// |
718 |
26 Dec 06 |
jari |
/// Function returning error of predictions |
430 |
08 Dec 05 |
peter |
99 |
/// |
1120 |
21 Feb 08 |
peter |
100 |
const utility::Vector& y_err(void) const; |
235 |
21 Feb 05 |
peter |
101 |
|
216 |
29 Dec 04 |
peter |
102 |
private: |
383 |
12 Aug 05 |
jari |
103 |
/// |
383 |
12 Aug 05 |
jari |
/// Copy Constructor. (Not implemented) |
383 |
12 Aug 05 |
jari |
105 |
/// |
383 |
12 Aug 05 |
jari |
106 |
Local(const Local&); |
383 |
12 Aug 05 |
jari |
107 |
|
216 |
29 Dec 04 |
peter |
108 |
std::vector<std::pair<double, double> > data_; |
295 |
29 Apr 05 |
peter |
109 |
Kernel* kernel_; |
429 |
08 Dec 05 |
peter |
110 |
OneDimensionalWeighted* regressor_; |
1120 |
21 Feb 08 |
peter |
111 |
utility::Vector x_; |
4200 |
19 Aug 22 |
peter |
112 |
utility::Vector y_predicted_; |
4200 |
19 Aug 22 |
peter |
113 |
utility::Vector y_err_; |
202 |
01 Nov 04 |
peter |
114 |
}; |
202 |
01 Nov 04 |
peter |
115 |
|
430 |
08 Dec 05 |
peter |
116 |
/// |
726 |
04 Jan 07 |
peter |
/// The output operator for the Regression::Local class. |
430 |
08 Dec 05 |
peter |
118 |
/// |
1885 |
31 Mar 09 |
peter |
/// \relates Local |
1885 |
31 Mar 09 |
peter |
120 |
/// |
430 |
08 Dec 05 |
peter |
121 |
std::ostream& operator<<(std::ostream&, const Local& ); |
202 |
01 Nov 04 |
peter |
122 |
|
681 |
11 Oct 06 |
jari |
123 |
}}} // of namespaces regression, yat, and theplu |
430 |
08 Dec 05 |
peter |
124 |
|
202 |
01 Nov 04 |
peter |
125 |
#endif |