1 | #ifndef _theplu_yat_regression_multidimensionalweighted_ |
---|
2 | #define _theplu_yat_regression_multidimensionalweighted_ |
---|
3 | |
---|
4 | // $Id: MultiDimensionalWeighted.h 2119 2009-12-12 23:11:43Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
8 | |
---|
9 | This file is part of the yat library, http://dev.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 3 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 yat. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "yat/utility/Matrix.h" |
---|
26 | #include "yat/utility/Vector.h" |
---|
27 | |
---|
28 | #include <gsl/gsl_multifit.h> |
---|
29 | |
---|
30 | namespace theplu { |
---|
31 | namespace yat { |
---|
32 | namespace regression { |
---|
33 | |
---|
34 | /// |
---|
35 | /// @brief MultiDimesional fitting. |
---|
36 | /// |
---|
37 | class MultiDimensionalWeighted |
---|
38 | { |
---|
39 | public: |
---|
40 | |
---|
41 | /// |
---|
42 | /// @brief Default Constructor |
---|
43 | /// |
---|
44 | MultiDimensionalWeighted(void); |
---|
45 | |
---|
46 | /// |
---|
47 | /// @brief Destructor |
---|
48 | /// |
---|
49 | ~MultiDimensionalWeighted(void); |
---|
50 | |
---|
51 | /// |
---|
52 | /// @return sum of squared residuals |
---|
53 | /// |
---|
54 | double chisq(void) const; |
---|
55 | |
---|
56 | /** |
---|
57 | \see gsl_multifit_wlinear |
---|
58 | |
---|
59 | \throw A GSL_error exception is thrown if memory allocation |
---|
60 | fails or the underlying GSL calls fails (usually matrix |
---|
61 | dimension errors). |
---|
62 | */ |
---|
63 | void fit(const utility::Matrix& X, const utility::VectorBase& y, |
---|
64 | const utility::VectorBase& w); |
---|
65 | |
---|
66 | /// |
---|
67 | /// @return value in @a x according to fitted model |
---|
68 | /// |
---|
69 | double predict(const utility::VectorBase& x) const; |
---|
70 | |
---|
71 | /// |
---|
72 | /// @return expected squared prediction error for a new data point |
---|
73 | /// in @a x |
---|
74 | /// |
---|
75 | double prediction_error2(const utility::VectorBase& x, const double w=1) const; |
---|
76 | |
---|
77 | /// |
---|
78 | /// @return error of model value in @a x |
---|
79 | /// |
---|
80 | double standard_error2(const utility::VectorBase& x) const; |
---|
81 | |
---|
82 | /// |
---|
83 | /// @return parameters of fitted model |
---|
84 | /// |
---|
85 | const utility::Vector& fit_parameters(void) const; |
---|
86 | |
---|
87 | /// |
---|
88 | /// @return variance of residuals |
---|
89 | /// |
---|
90 | double s2(const double w=1.0) const; |
---|
91 | |
---|
92 | private: |
---|
93 | double chisquare_; |
---|
94 | utility::Matrix covariance_; |
---|
95 | utility::Vector fit_parameters_; |
---|
96 | double s2_; |
---|
97 | gsl_multifit_linear_workspace* work_; |
---|
98 | |
---|
99 | }; |
---|
100 | |
---|
101 | }}} // of namespaces regression, yat, and theplu |
---|
102 | |
---|
103 | #endif |
---|