681 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_regression_multidimensional_ |
681 |
11 Oct 06 |
jari |
2 |
#define _theplu_yat_regression_multidimensional_ |
386 |
14 Aug 05 |
jari |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
386 |
14 Aug 05 |
jari |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
3661 |
14 Jul 17 |
peter |
Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2009, 2017, 2022 Peter Johansson |
616 |
31 Aug 06 |
jari |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
11 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
16 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
21 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
24 |
*/ |
675 |
10 Oct 06 |
jari |
25 |
|
3614 |
06 Feb 17 |
peter |
26 |
#include "Multivariate.h" |
3614 |
06 Feb 17 |
peter |
27 |
|
1121 |
22 Feb 08 |
peter |
28 |
#include "yat/utility/Matrix.h" |
2126 |
22 Dec 09 |
peter |
29 |
#include "yat/utility/Vector.h" |
675 |
10 Oct 06 |
jari |
30 |
|
386 |
14 Aug 05 |
jari |
31 |
#include <gsl/gsl_multifit.h> |
386 |
14 Aug 05 |
jari |
32 |
|
386 |
14 Aug 05 |
jari |
33 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
34 |
namespace yat { |
386 |
14 Aug 05 |
jari |
35 |
namespace regression { |
386 |
14 Aug 05 |
jari |
36 |
|
3614 |
06 Feb 17 |
peter |
37 |
/** |
3614 |
06 Feb 17 |
peter |
\brief Linear MultiDimesional regression |
3614 |
06 Feb 17 |
peter |
39 |
*/ |
3614 |
06 Feb 17 |
peter |
40 |
class MultiDimensional : public Multivariate |
386 |
14 Aug 05 |
jari |
41 |
{ |
386 |
14 Aug 05 |
jari |
42 |
public: |
386 |
14 Aug 05 |
jari |
43 |
|
386 |
14 Aug 05 |
jari |
44 |
/// |
389 |
15 Aug 05 |
peter |
/// @brief Default Constructor |
386 |
14 Aug 05 |
jari |
46 |
/// |
703 |
18 Dec 06 |
jari |
47 |
MultiDimensional(void); |
386 |
14 Aug 05 |
jari |
48 |
|
386 |
14 Aug 05 |
jari |
49 |
/// |
386 |
14 Aug 05 |
jari |
/// @brief Destructor |
386 |
14 Aug 05 |
jari |
51 |
/// |
703 |
18 Dec 06 |
jari |
52 |
~MultiDimensional(void); |
386 |
14 Aug 05 |
jari |
53 |
|
3611 |
31 Jan 17 |
peter |
54 |
/** |
3611 |
31 Jan 17 |
peter |
\brief covariance of parameters |
3611 |
31 Jan 17 |
peter |
56 |
|
3614 |
06 Feb 17 |
peter |
The covariance of fit parameters is calculated as \f$ \sigma^2 |
3614 |
06 Feb 17 |
peter |
(X'X)^{-1} \f$ where \f$ \sigma^2\f$ is the variance of error |
3614 |
06 Feb 17 |
peter |
residuals. |
3611 |
31 Jan 17 |
peter |
60 |
*/ |
1121 |
22 Feb 08 |
peter |
61 |
const utility::Matrix& covariance(void) const; |
726 |
04 Jan 07 |
peter |
62 |
|
751 |
17 Feb 07 |
jari |
63 |
/** |
751 |
17 Feb 07 |
jari |
\brief Function fitting parameters of the linear model by |
751 |
17 Feb 07 |
jari |
miminizing the quadratic deviation between model and data. |
751 |
17 Feb 07 |
jari |
66 |
|
1449 |
28 Aug 08 |
peter |
Number of rows in \a X must match size of \a y. |
1449 |
28 Aug 08 |
peter |
68 |
|
751 |
17 Feb 07 |
jari |
\throw A GSL_error exception is thrown if memory allocation |
751 |
17 Feb 07 |
jari |
fails or the underlying GSL calls fails (usually matrix |
751 |
17 Feb 07 |
jari |
dimension errors). |
4130 |
20 Jan 22 |
peter |
72 |
|
4130 |
20 Jan 22 |
peter |
\since New in yat 0.20 |
751 |
17 Feb 07 |
jari |
74 |
*/ |
4130 |
20 Jan 22 |
peter |
75 |
void fit2(const utility::MatrixBase& X, const utility::VectorBase& y); |
4130 |
20 Jan 22 |
peter |
76 |
|
4130 |
20 Jan 22 |
peter |
77 |
/** |
4130 |
20 Jan 22 |
peter |
Just kept for back compatibility with yat 0.19. Exactly the |
4130 |
20 Jan 22 |
peter |
same behaviour as for fit2. |
4130 |
20 Jan 22 |
peter |
80 |
*/ |
1121 |
22 Feb 08 |
peter |
81 |
void fit(const utility::Matrix& X, const utility::VectorBase& y); |
386 |
14 Aug 05 |
jari |
82 |
|
386 |
14 Aug 05 |
jari |
83 |
/// |
648 |
14 Sep 06 |
peter |
/// @return parameters of the model |
386 |
14 Aug 05 |
jari |
85 |
/// |
1120 |
21 Feb 08 |
peter |
86 |
const utility::Vector& fit_parameters(void) const; |
386 |
14 Aug 05 |
jari |
87 |
|
713 |
21 Dec 06 |
peter |
88 |
/** |
731 |
06 Jan 07 |
peter |
@brief Summed Squared Error |
713 |
21 Dec 06 |
peter |
90 |
*/ |
713 |
21 Dec 06 |
peter |
91 |
double chisq(void) const; |
713 |
21 Dec 06 |
peter |
92 |
|
586 |
19 Jun 06 |
peter |
93 |
/// |
586 |
19 Jun 06 |
peter |
/// @return value in @a x according to fitted model |
586 |
19 Jun 06 |
peter |
95 |
/// |
1021 |
01 Feb 08 |
peter |
96 |
double predict(const utility::VectorBase& x) const; |
586 |
19 Jun 06 |
peter |
97 |
|
586 |
19 Jun 06 |
peter |
98 |
/// |
727 |
04 Jan 07 |
peter |
/// @return expected squared prediction error for a new data point |
727 |
04 Jan 07 |
peter |
/// in @a x |
586 |
19 Jun 06 |
peter |
101 |
/// |
1021 |
01 Feb 08 |
peter |
102 |
double prediction_error2(const utility::VectorBase& x) const; |
586 |
19 Jun 06 |
peter |
103 |
|
586 |
19 Jun 06 |
peter |
104 |
/// |
727 |
04 Jan 07 |
peter |
/// @return squared error of model value in @a x |
586 |
19 Jun 06 |
peter |
106 |
/// |
1021 |
01 Feb 08 |
peter |
107 |
double standard_error2(const utility::VectorBase& x) const; |
586 |
19 Jun 06 |
peter |
108 |
|
386 |
14 Aug 05 |
jari |
109 |
private: |
2126 |
22 Dec 09 |
peter |
// no copy allowed |
2126 |
22 Dec 09 |
peter |
111 |
MultiDimensional(const MultiDimensional&); |
2126 |
22 Dec 09 |
peter |
112 |
MultiDimensional& operator=(const MultiDimensional&); |
2126 |
22 Dec 09 |
peter |
113 |
|
386 |
14 Aug 05 |
jari |
114 |
double chisquare_; |
739 |
12 Jan 07 |
peter |
115 |
double s2_; |
1121 |
22 Feb 08 |
peter |
116 |
utility::Matrix covariance_; |
1120 |
21 Feb 08 |
peter |
117 |
utility::Vector fit_parameters_; |
386 |
14 Aug 05 |
jari |
118 |
gsl_multifit_linear_workspace* work_; |
386 |
14 Aug 05 |
jari |
119 |
|
386 |
14 Aug 05 |
jari |
120 |
}; |
386 |
14 Aug 05 |
jari |
121 |
|
681 |
11 Oct 06 |
jari |
122 |
}}} // of namespaces regression, yat, and theplu |
386 |
14 Aug 05 |
jari |
123 |
|
386 |
14 Aug 05 |
jari |
124 |
#endif |