source: trunk/yat/regression/OneDimensional.h @ 1650

Last change on this file since 1650 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1#ifndef _theplu_yat_regression_onedimensional_
2#define _theplu_yat_regression_onedimensional_
3
4// $Id: OneDimensional.h 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2004 Peter Johansson
8  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2008 Peter Johansson
10
11  This file is part of the yat library, http://dev.thep.lu.se/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 3 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with yat. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#include "yat/statistics/AveragerPair.h"
28
29#include <ostream>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34  class VectorBase;
35}
36namespace regression {
37
38  ///
39  /// @brief Interface Class for One Dimensional fitting.   
40  ///
41  /// @see OneDimensionalWeighted.
42  ///
43  class OneDimensional
44  {
45
46  public:
47    ///
48    /// @brief The default constructor
49    ///
50    OneDimensional(void);
51
52    ///
53    /// @brief The destructor
54    ///
55    virtual ~OneDimensional(void);
56 
57    /**
58       @brief Chi-squared
59       
60       Chi-squared is defined as the \f$
61       \sum{(\hat{y_i}-y_i)^2} \f$
62    */
63    double chisq(void) const;
64   
65    /**
66       This function computes the best-fit given a model (see specific
67       class for details) by minimizing \f$ \sum{(\hat{y_i}-y_i)^2}
68       \f$, where \f$ \hat{y} \f$ is the fitted value.
69    */
70    virtual void fit(const utility::VectorBase& x, 
71                     const utility::VectorBase& y)=0; 
72   
73    ///
74    /// @return expected value in @a x accrding to the fitted model
75    ///
76    virtual double predict(const double x) const=0;
77   
78    /**
79       The prediction error is defined as the expected squared
80       deviation a new data point will have from value the model
81       provides: \f$ E(Y|x - \hat{y}(x))^2 \f$ and is typically
82       divided into the conditional variance ( see s2() )
83       given \f$ x \f$ and the squared standard error ( see
84       standard_error2() ) of the model estimation in \f$ x \f$.
85       
86       @return expected squared prediction error for a new data point
87       in @a x
88    */
89    double prediction_error2(const double x) const; 
90
91    ///
92    /// @brief print output to ostream @a os
93    ///
94    /// Printing estimated model to @a os in the points defined by @a
95    /// min, @a max, and @a n. The values printed for each point is
96    /// the x-value, the estimated y-value, and the estimated standard
97    /// deviation of a new data poiunt will have from the y-value
98    /// given the x-value (see prediction_error()).
99    ///
100    /// @param os Ostream printout is sent to
101    /// @param n number of points printed
102    /// @param min smallest x-value for which the model is printed
103    /// @param max largest x-value for which the model is printed
104    ///
105    std::ostream& print(std::ostream& os,const double min, 
106                        double max, const unsigned int n) const;
107
108    /**
109       r2 is defined as \f$ 1 - \frac{Var(Y|x)}{Var(Y)} \f$ or the
110       fraction of the variance explained by the regression model.
111
112       @see s2()
113    */
114    double r2(void) const;
115
116    /**
117       \f$ E(Y|x - E(Y|x))^2 \f$
118
119       @return Conditional variance of Y
120    */
121    virtual double s2(void) const=0;
122
123    /**
124       The standard error is defined as \f$ E(Y|x - \hat{y}(x))^2 \f$
125
126       @return expected squared error of model value in @a x
127    */
128    virtual double standard_error2(const double x) const=0;
129
130  protected:
131    ///
132    /// Variance of y
133    ///
134    double variance(void) const;
135
136    ///
137    /// Averager for pair of x and y
138    ///
139    statistics::AveragerPair ap_;
140
141    ///
142    /// @see chisq()
143    ///
144    double chisq_;
145  };
146
147}}} // of namespaces regression, yat, and theplu
148
149#endif
Note: See TracBrowser for help on using the repository browser.