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

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

refs #867 and #882. Interface for Negative Binomiual and Poisson regression

  • 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 3614 2017-02-06 01:37:33Z peter $
5
6/*
7  Copyright (C) 2009 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "Multivariate.h"
26
27#include "yat/utility/Matrix.h"
28#include "yat/utility/Vector.h"
29
30#include <gsl/gsl_multifit.h>
31
32namespace theplu {
33namespace yat {
34namespace regression {
35
36  /**
37     \brief Linear MultiDimesional regression
38  */
39  class MultiDimensional : public Multivariate
40  {
41  public:
42
43    ///
44    /// @brief Default Constructor
45    ///
46    MultiDimensional(void);
47
48    ///
49    /// @brief Destructor
50    ///
51    ~MultiDimensional(void);
52
53    /**
54       \brief covariance of parameters
55
56       The covariance of fit parameters is calculated as \f$ \sigma^2
57       (X'X)^{-1} \f$ where \f$ \sigma^2\f$ is the variance of error
58       residuals.
59    */
60    const utility::Matrix& covariance(void) const;
61
62    /**
63       \brief Function fitting parameters of the linear model by
64       miminizing the quadratic deviation between model and data.
65
66       Number of rows in \a X must match size of \a y.
67
68       \throw A GSL_error exception is thrown if memory allocation
69       fails or the underlying GSL calls fails (usually matrix
70       dimension errors).
71    */
72    void fit(const utility::Matrix& X, const utility::VectorBase& y);
73
74    ///
75    /// @return parameters of the model
76    ///
77    const utility::Vector& fit_parameters(void) const;
78
79    /**
80       @brief Summed Squared Error
81     */
82    double chisq(void) const;
83
84    ///
85    /// @return value in @a x according to fitted model
86    ///
87    double predict(const utility::VectorBase& x) const;
88
89    ///
90    /// @return expected squared prediction error for a new data point
91    /// in @a x
92    ///
93    double prediction_error2(const utility::VectorBase& x) const;
94
95    ///
96    /// @return squared error of model value in @a x
97    ///
98    double standard_error2(const utility::VectorBase& x) const;
99
100  private:
101    // no copy allowed
102    MultiDimensional(const MultiDimensional&);
103    MultiDimensional& operator=(const MultiDimensional&);
104
105    double chisquare_;
106    double s2_;
107    utility::Matrix covariance_;
108    utility::Vector fit_parameters_;
109    gsl_multifit_linear_workspace* work_;
110
111  };
112
113}}} // of namespaces regression, yat, and theplu
114
115#endif
Note: See TracBrowser for help on using the repository browser.