1 | #ifndef _theplu_yat_regression_polynomialweighted_ |
---|
2 | #define _theplu_yat_regression_polynomialweighted_ |
---|
3 | |
---|
4 | // $Id: PolynomialWeighted.h 1000 2007-12-23 20:09:15Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
8 | |
---|
9 | This file is part of the yat library, http://trac.thep.lu.se/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 "OneDimensionalWeighted.h" |
---|
28 | #include "MultiDimensionalWeighted.h" |
---|
29 | #include "yat/utility/vector.h" |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace regression { |
---|
34 | |
---|
35 | /// |
---|
36 | /// @brief Polynomial Regression in weighted fashion. |
---|
37 | /// |
---|
38 | class PolynomialWeighted : public OneDimensionalWeighted |
---|
39 | { |
---|
40 | public: |
---|
41 | |
---|
42 | /// |
---|
43 | /// @param power degree of polynomial model |
---|
44 | /// |
---|
45 | PolynomialWeighted(size_t power); |
---|
46 | |
---|
47 | /// |
---|
48 | /// @brief Destructor |
---|
49 | /// |
---|
50 | ~PolynomialWeighted(void); |
---|
51 | |
---|
52 | /// |
---|
53 | /// This function computes the best-fit given the polynomial model |
---|
54 | /// model by minimizing \f$ \sum{w_i(\hat{y_i}-y_i)^2} \f$, where |
---|
55 | /// \f$ \hat{y} \f$ is the fitted value. The weight \f$ w_i \f$ |
---|
56 | /// should be proportional to the inverse of the variance for \f$ |
---|
57 | /// y_i \f$ |
---|
58 | /// |
---|
59 | void fit(const utility::vector& x, const utility::vector& y, |
---|
60 | const utility::vector& w); |
---|
61 | |
---|
62 | /// |
---|
63 | /// @return parameters of the model |
---|
64 | /// |
---|
65 | /// @see MultiDimensional |
---|
66 | /// |
---|
67 | const utility::vector& fit_parameters(void) const; |
---|
68 | |
---|
69 | /// |
---|
70 | /// @return parameters for polynomial model |
---|
71 | /// |
---|
72 | utility::vector fit_parameters(void) { return md_.fit_parameters(); } |
---|
73 | |
---|
74 | /// |
---|
75 | /// @brief Mean Squared Error |
---|
76 | /// |
---|
77 | double s2(const double w=1) const; |
---|
78 | |
---|
79 | /// |
---|
80 | /// function predicting in one point. |
---|
81 | /// |
---|
82 | double predict(const double x) const; |
---|
83 | |
---|
84 | /// |
---|
85 | /// @return error of model value in @a x |
---|
86 | /// |
---|
87 | double standard_error2(const double x) const; |
---|
88 | |
---|
89 | private: |
---|
90 | MultiDimensionalWeighted md_; |
---|
91 | size_t power_; |
---|
92 | |
---|
93 | }; |
---|
94 | |
---|
95 | }}} // of namespaces regression, yat, and theplu |
---|
96 | |
---|
97 | #endif |
---|