1 | #ifndef _theplu_yat_regression_polynomial_ |
---|
2 | #define _theplu_yat_regression_polynomial_ |
---|
3 | |
---|
4 | // $Id: Polynomial.h 1392 2008-07-28 19:35:30Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005, 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 "OneDimensional.h" |
---|
29 | #include "MultiDimensional.h" |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace utility { |
---|
34 | class VectorBase; |
---|
35 | } |
---|
36 | namespace regression { |
---|
37 | |
---|
38 | /** |
---|
39 | @brief Polynomial regression |
---|
40 | |
---|
41 | Data are modeled as \f$ y = \alpha + \beta x + \gamma x^2 + |
---|
42 | ... + \delta x_i^{\textrm{power}} + \epsilon_i \f$ |
---|
43 | */ |
---|
44 | class Polynomial : public OneDimensional |
---|
45 | { |
---|
46 | public: |
---|
47 | |
---|
48 | /// |
---|
49 | /// @param power degree of polynomial, e.g. 1 for a linear model |
---|
50 | /// |
---|
51 | explicit Polynomial(size_t power); |
---|
52 | |
---|
53 | /// |
---|
54 | /// @brief Destructor |
---|
55 | /// |
---|
56 | ~Polynomial(void); |
---|
57 | |
---|
58 | /// |
---|
59 | /// @brief covariance of parameters |
---|
60 | /// |
---|
61 | const utility::Matrix& covariance(void) const; |
---|
62 | |
---|
63 | /// |
---|
64 | /// Fit the model by minimizing the mean squared deviation between |
---|
65 | /// model and data. |
---|
66 | /// |
---|
67 | void fit(const utility::VectorBase& x, const utility::VectorBase& y); |
---|
68 | |
---|
69 | /// |
---|
70 | /// @return parameters of the model |
---|
71 | /// |
---|
72 | /// @see MultiDimensional |
---|
73 | /// |
---|
74 | const utility::Vector& fit_parameters(void) const; |
---|
75 | |
---|
76 | /// |
---|
77 | /// @return value in @a x of model |
---|
78 | /// |
---|
79 | double predict(const double x) const; |
---|
80 | |
---|
81 | /** |
---|
82 | \f$ \frac{\sum \epsilon_i^2}{N-\textrm{DF}} \f$ |
---|
83 | where DF is number of parameters in model. |
---|
84 | |
---|
85 | @return variance of residuals |
---|
86 | */ |
---|
87 | double s2(void) const; |
---|
88 | |
---|
89 | /// |
---|
90 | /// @return squared error of model value in @a x |
---|
91 | /// |
---|
92 | double standard_error2(const double x) const; |
---|
93 | |
---|
94 | private: |
---|
95 | MultiDimensional md_; |
---|
96 | size_t power_; |
---|
97 | |
---|
98 | }; |
---|
99 | |
---|
100 | }}} // of namespaces regression, yat, and theplu |
---|
101 | |
---|
102 | #endif |
---|