1 | #ifndef _theplu_yat_regression_multidimensional_ |
---|
2 | #define _theplu_yat_regression_multidimensional_ |
---|
3 | |
---|
4 | // $Id: MultiDimensional.h 1486 2008-09-09 21:17:19Z jari $ |
---|
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 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 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 "yat/utility/Matrix.h" |
---|
29 | #include "yat/utility/VectorBase.h" |
---|
30 | |
---|
31 | #include <gsl/gsl_multifit.h> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace regression { |
---|
36 | |
---|
37 | /// |
---|
38 | /// @brief MultiDimesional fitting. |
---|
39 | /// |
---|
40 | class MultiDimensional |
---|
41 | { |
---|
42 | public: |
---|
43 | |
---|
44 | /// |
---|
45 | /// @brief Default Constructor |
---|
46 | /// |
---|
47 | MultiDimensional(void); |
---|
48 | |
---|
49 | /// |
---|
50 | /// @brief Destructor |
---|
51 | /// |
---|
52 | ~MultiDimensional(void); |
---|
53 | |
---|
54 | /// |
---|
55 | /// @brief covariance of parameters |
---|
56 | /// |
---|
57 | const utility::Matrix& covariance(void) const; |
---|
58 | |
---|
59 | /** |
---|
60 | \brief Function fitting parameters of the linear model by |
---|
61 | miminizing the quadratic deviation between model and data. |
---|
62 | |
---|
63 | Number of rows in \a X must match size of \a y. |
---|
64 | |
---|
65 | \throw A GSL_error exception is thrown if memory allocation |
---|
66 | fails or the underlying GSL calls fails (usually matrix |
---|
67 | dimension errors). |
---|
68 | */ |
---|
69 | void fit(const utility::Matrix& X, const utility::VectorBase& y); |
---|
70 | |
---|
71 | /// |
---|
72 | /// @return parameters of the model |
---|
73 | /// |
---|
74 | const utility::Vector& fit_parameters(void) const; |
---|
75 | |
---|
76 | /** |
---|
77 | @brief Summed Squared Error |
---|
78 | */ |
---|
79 | double chisq(void) const; |
---|
80 | |
---|
81 | /// |
---|
82 | /// @return value in @a x according to fitted model |
---|
83 | /// |
---|
84 | double predict(const utility::VectorBase& x) const; |
---|
85 | |
---|
86 | /// |
---|
87 | /// @return expected squared prediction error for a new data point |
---|
88 | /// in @a x |
---|
89 | /// |
---|
90 | double prediction_error2(const utility::VectorBase& x) const; |
---|
91 | |
---|
92 | /// |
---|
93 | /// @return squared error of model value in @a x |
---|
94 | /// |
---|
95 | double standard_error2(const utility::VectorBase& x) const; |
---|
96 | |
---|
97 | private: |
---|
98 | double chisquare_; |
---|
99 | double s2_; |
---|
100 | utility::Matrix covariance_; |
---|
101 | utility::Vector fit_parameters_; |
---|
102 | gsl_multifit_linear_workspace* work_; |
---|
103 | |
---|
104 | }; |
---|
105 | |
---|
106 | }}} // of namespaces regression, yat, and theplu |
---|
107 | |
---|
108 | #endif |
---|