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