# source:trunk/yat/regression/Polynomial.h@729

Last change on this file since 729 was 729, checked in by Peter, 17 years ago

Fixes #159. Also removed some inlines in OneDimensionalWeighted? by adding source file. Refs #81

• Property svn:eol-style set to native
• Property svn:keywords set to Id
File size: 2.3 KB
Line
1#ifndef _theplu_yat_regression_polynomial_
2#define _theplu_yat_regression_polynomial_
3
4// $Id: Polynomial.h 729 2007-01-05 16:00:15Z peter$
5
6/*
7  Copyright (C) The authors contributing to this file.
8
9  This file is part of the yat library, http://lev.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "OneDimensional.h"
28#include "MultiDimensional.h"
29#include "yat/utility/vector.h"
30
31namespace theplu {
32namespace yat {
33namespace regression {
34
35  /**
36     @brief Polynomial regression
37
38     Data are modeled as \f$y = \alpha + \beta x + \gamma x^2 + 39 ... + \delta x_i^{\textrm{power}} + \epsilon_i \f$
40  */
41  class Polynomial : public OneDimensional
42  {
43  public:
44
45    ///
46    /// @param power degree of polynomial, e.g. 1 for a linear model
47    ///
48    explicit Polynomial(size_t power);
49
50    ///
51    /// @brief Destructor
52    ///
53    ~Polynomial(void);
54
55    ///
56    /// @brief covariance of parameters
57    ///
58    const utility::matrix& covariance(void) const;
59
60    ///
61    /// Fit the model by minimizing the mean squared deviation between
62    /// model and data.
63    ///
64    void fit(const utility::vector& x, const utility::vector& y);
65
66    ///
67    /// @return parameters of the model
68    ///
69    /// @see MultiDimensional
70    ///
71    const utility::vector& fit_parameters(void) const;
72
73    ///
74    /// @return value in @a x of model
75    ///
76    double predict(const double x) const;
77
78    /**
79       \f$\frac{\sum \epsilon_i^2}{N-\textrm{DF}} \f$
80       where DF is number of parameters in model.
81
82       @return variance of residuals
83    */
84    double s2(void) const;
85
86    ///
87    /// @return squared error of model value in @a x
88    ///
89    double standard_error2(const double x) const;
90
91  private:
92    MultiDimensional md_;
93    size_t power_;
94
95  };
96
97}}} // of namespaces regression, yat, and theplu
98
99#endif
Note: See TracBrowser for help on using the repository browser.