1 | #ifndef _theplu_yat_regression_polynomialweighted_ |
---|
2 | #define _theplu_yat_regression_polynomialweighted_ |
---|
3 | |
---|
4 | // $Id: PolynomialWeighted.h 1392 2008-07-28 19:35:30Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2008 Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 2 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with this program; if not, write to the Free Software |
---|
24 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
25 | 02111-1307, USA. |
---|
26 | */ |
---|
27 | |
---|
28 | #include "OneDimensionalWeighted.h" |
---|
29 | #include "MultiDimensionalWeighted.h" |
---|
30 | #include "yat/utility/Vector.h" |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace regression { |
---|
35 | |
---|
36 | /// |
---|
37 | /// @brief Polynomial Regression in weighted fashion. |
---|
38 | /// |
---|
39 | class PolynomialWeighted : public OneDimensionalWeighted |
---|
40 | { |
---|
41 | public: |
---|
42 | |
---|
43 | /// |
---|
44 | /// @param power degree of polynomial model |
---|
45 | /// |
---|
46 | PolynomialWeighted(size_t power); |
---|
47 | |
---|
48 | /// |
---|
49 | /// @brief Destructor |
---|
50 | /// |
---|
51 | ~PolynomialWeighted(void); |
---|
52 | |
---|
53 | /// |
---|
54 | /// This function computes the best-fit given the polynomial model |
---|
55 | /// model by minimizing \f$ \sum{w_i(\hat{y_i}-y_i)^2} \f$, where |
---|
56 | /// \f$ \hat{y} \f$ is the fitted value. The weight \f$ w_i \f$ |
---|
57 | /// should be proportional to the inverse of the variance for \f$ |
---|
58 | /// y_i \f$ |
---|
59 | /// |
---|
60 | void fit(const utility::VectorBase& x, const utility::VectorBase& y, |
---|
61 | const utility::VectorBase& w); |
---|
62 | |
---|
63 | /// |
---|
64 | /// @return parameters of the model |
---|
65 | /// |
---|
66 | /// @see MultiDimensional |
---|
67 | /// |
---|
68 | const utility::Vector& fit_parameters(void) const; |
---|
69 | |
---|
70 | /// |
---|
71 | /// @brief Mean Squared Error |
---|
72 | /// |
---|
73 | double s2(const double w=1) const; |
---|
74 | |
---|
75 | /// |
---|
76 | /// function predicting in one point. |
---|
77 | /// |
---|
78 | double predict(const double x) const; |
---|
79 | |
---|
80 | /// |
---|
81 | /// @return error of model value in @a x |
---|
82 | /// |
---|
83 | double standard_error2(const double x) const; |
---|
84 | |
---|
85 | private: |
---|
86 | MultiDimensionalWeighted md_; |
---|
87 | size_t power_; |
---|
88 | |
---|
89 | }; |
---|
90 | |
---|
91 | }}} // of namespaces regression, yat, and theplu |
---|
92 | |
---|
93 | #endif |
---|