source: trunk/yat/regression/MultiDimensional.h @ 3611

Last change on this file since 3611 was 3611, checked in by Peter, 6 years ago

document how covariance is calculated

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_yat_regression_multidimensional_
2#define _theplu_yat_regression_multidimensional_
3
4// $Id: MultiDimensional.h 3611 2017-01-31 02:16:25Z peter $
5
6/*
7  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009 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
31namespace theplu {
32namespace yat {
33namespace regression {
34
35  ///
36  /// @brief MultiDimesional fitting.
37  ///
38  class MultiDimensional
39  {
40  public:
41
42    ///
43    /// @brief Default Constructor
44    ///
45    MultiDimensional(void);
46
47    ///
48    /// @brief Destructor
49    ///
50    ~MultiDimensional(void);
51
52    /**
53       \brief covariance of parameters
54
55       The covariance of fit parameters are calculated as \f$ \sigma^2
56       (X'X)^{-1} \f$ where \f$ \sigma^2 \f$ is the variance of the of
57       the error terms.
58    */
59    const utility::Matrix& covariance(void) const;
60
61    /**
62       \brief Function fitting parameters of the linear model by
63       miminizing the quadratic deviation between model and data.
64
65       Number of rows in \a X must match size of \a y.
66
67       \throw A GSL_error exception is thrown if memory allocation
68       fails or the underlying GSL calls fails (usually matrix
69       dimension errors).
70    */
71    void fit(const utility::Matrix& X, const utility::VectorBase& y);
72
73    ///
74    /// @return parameters of the model
75    ///
76    const utility::Vector& fit_parameters(void) const;
77
78    /**
79       @brief Summed Squared Error
80     */
81    double chisq(void) const;
82
83    ///
84    /// @return value in @a x according to fitted model
85    ///
86    double predict(const utility::VectorBase& x) const;
87
88    ///
89    /// @return expected squared prediction error for a new data point
90    /// in @a x
91    ///
92    double prediction_error2(const utility::VectorBase& x) const;
93
94    ///
95    /// @return squared error of model value in @a x
96    ///
97    double standard_error2(const utility::VectorBase& x) const;
98
99  private:
100    // no copy allowed
101    MultiDimensional(const MultiDimensional&);
102    MultiDimensional& operator=(const MultiDimensional&);
103
104    double chisquare_;
105    double s2_;
106    utility::Matrix covariance_;
107    utility::Vector fit_parameters_;
108    gsl_multifit_linear_workspace* work_;
109
110  };
111
112}}} // of namespaces regression, yat, and theplu
113
114#endif
Note: See TracBrowser for help on using the repository browser.