1 | #ifndef _theplu_statistics_regression_polynomial_weighted_ |
---|
2 | #define _theplu_statistics_regression_polynomial_weighted_ |
---|
3 | |
---|
4 | // $Id: PolynomialWeighted.h 675 2006-10-10 12:08:45Z 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 "yat/statistics/OneDimensionalWeighted.h" |
---|
28 | #include "yat/statistics/MultiDimensionalWeighted.h" |
---|
29 | |
---|
30 | #include "yat/utility/vector.h" |
---|
31 | |
---|
32 | #include <cassert> |
---|
33 | |
---|
34 | |
---|
35 | namespace theplu { |
---|
36 | namespace statistics { |
---|
37 | namespace regression { |
---|
38 | |
---|
39 | /// |
---|
40 | /// @todo document |
---|
41 | /// |
---|
42 | class PolynomialWeighted : public OneDimensionalWeighted |
---|
43 | { |
---|
44 | public: |
---|
45 | |
---|
46 | /// |
---|
47 | /// @param power degree of polynomial model |
---|
48 | /// |
---|
49 | inline PolynomialWeighted(size_t power) |
---|
50 | : OneDimensionalWeighted(), power_(power) {} |
---|
51 | |
---|
52 | /// |
---|
53 | /// @brief Destructor |
---|
54 | /// |
---|
55 | inline ~PolynomialWeighted(void) {}; |
---|
56 | |
---|
57 | /// |
---|
58 | /// This function computes the best-fit given the polynomial model |
---|
59 | /// model by minimizing \f$ \sum{w_i(\hat{y_i}-y_i)^2} \f$, where |
---|
60 | /// \f$ \hat{y} \f$ is the fitted value. The weight \f$ w_i \f$ |
---|
61 | /// should be proportional to the inverse of the variance for \f$ |
---|
62 | /// y_i \f$ |
---|
63 | /// |
---|
64 | void fit(const utility::vector& x, const utility::vector& y, |
---|
65 | const utility::vector& w); |
---|
66 | |
---|
67 | /// |
---|
68 | /// @return parameters for polynomial model |
---|
69 | /// |
---|
70 | utility::vector fit_parameters(void) { return md_.fit_parameters(); } |
---|
71 | |
---|
72 | /// |
---|
73 | /// function predicting in one point. |
---|
74 | /// |
---|
75 | double predict(const double x) const; |
---|
76 | |
---|
77 | /// |
---|
78 | /// @return expected prediction error for a new data point in @a x |
---|
79 | /// with weight @a w |
---|
80 | /// |
---|
81 | double prediction_error(const double x, const double w=1) const; |
---|
82 | |
---|
83 | /// |
---|
84 | /// @return error of model value in @a x |
---|
85 | /// |
---|
86 | double standard_error(const double x) const; |
---|
87 | |
---|
88 | private: |
---|
89 | MultiDimensionalWeighted md_; |
---|
90 | size_t power_; |
---|
91 | |
---|
92 | }; |
---|
93 | |
---|
94 | |
---|
95 | }}} // of namespaces regression, statisitcs and thep |
---|
96 | |
---|
97 | #endif |
---|