source: trunk/yat/regression/MultiDimensional.h

Last change on this file was 3661, checked in by Peter, 4 years ago

update copyright years

  • 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 3661 2017-07-14 01:10:35Z peter $
5
6/*
7  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2017 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    void fit(const utility::Matrix& X, const utility::VectorBase& y);
74
75    ///
76    /// @return parameters of the model
77    ///
78    const utility::Vector& fit_parameters(void) const;
79
80    /**
81       @brief Summed Squared Error
82     */
83    double chisq(void) const;
84
85    ///
86    /// @return value in @a x according to fitted model
87    ///
88    double predict(const utility::VectorBase& x) const;
89
90    ///
91    /// @return expected squared prediction error for a new data point
92    /// in @a x
93    ///
94    double prediction_error2(const utility::VectorBase& x) const;
95
96    ///
97    /// @return squared error of model value in @a x
98    ///
99    double standard_error2(const utility::VectorBase& x) const;
100
101  private:
102    // no copy allowed
103    MultiDimensional(const MultiDimensional&);
104    MultiDimensional& operator=(const MultiDimensional&);
105
106    double chisquare_;
107    double s2_;
108    utility::Matrix covariance_;
109    utility::Vector fit_parameters_;
110    gsl_multifit_linear_workspace* work_;
111
112  };
113
114}}} // of namespaces regression, yat, and theplu
115
116#endif
Note: See TracBrowser for help on using the repository browser.