source: trunk/yat/regression/MultiDimensional.h

Last change on this file was 4207, checked in by Peter, 4 months ago

update copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1#ifndef _theplu_yat_regression_multidimensional_
2#define _theplu_yat_regression_multidimensional_
3
4// $Id: MultiDimensional.h 4207 2022-08-26 04:36:28Z peter $
5
6/*
7  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2017, 2022 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 "Multivariate.h"
27
28#include "yat/utility/Matrix.h"
29#include "yat/utility/Vector.h"
30
31#include <gsl/gsl_multifit.h>
32
33namespace theplu {
34namespace yat {
35namespace regression {
36
37  /**
38     \brief Linear MultiDimesional regression
39  */
40  class MultiDimensional : public Multivariate
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       The covariance of fit parameters is calculated as \f$ \sigma^2
58       (X'X)^{-1} \f$ where \f$ \sigma^2\f$ is the variance of error
59       residuals.
60    */
61    const utility::Matrix& covariance(void) const;
62
63    /**
64       \brief Function fitting parameters of the linear model by
65       miminizing the quadratic deviation between model and data.
66
67       Number of rows in \a X must match size of \a y.
68
69       \throw A GSL_error exception is thrown if memory allocation
70       fails or the underlying GSL calls fails (usually matrix
71       dimension errors).
72
73       \since New in yat 0.20
74    */
75    void fit2(const utility::MatrixBase& X, const utility::VectorBase& y);
76
77    /**
78       Just kept for back compatibility with yat 0.19. Exactly the
79       same behaviour as for fit2.
80     */
81    void fit(const utility::Matrix& X, const utility::VectorBase& y);
82
83    ///
84    /// @return parameters of the model
85    ///
86    const utility::Vector& fit_parameters(void) const;
87
88    /**
89       @brief Summed Squared Error
90     */
91    double chisq(void) const;
92
93    ///
94    /// @return value in @a x according to fitted model
95    ///
96    double predict(const utility::VectorBase& x) const;
97
98    ///
99    /// @return expected squared prediction error for a new data point
100    /// in @a x
101    ///
102    double prediction_error2(const utility::VectorBase& x) const;
103
104    ///
105    /// @return squared error of model value in @a x
106    ///
107    double standard_error2(const utility::VectorBase& x) const;
108
109  private:
110    // no copy allowed
111    MultiDimensional(const MultiDimensional&);
112    MultiDimensional& operator=(const MultiDimensional&);
113
114    double chisquare_;
115    double s2_;
116    utility::Matrix covariance_;
117    utility::Vector fit_parameters_;
118    gsl_multifit_linear_workspace* work_;
119
120  };
121
122}}} // of namespaces regression, yat, and theplu
123
124#endif
Note: See TracBrowser for help on using the repository browser.