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

Last change on this file since 2532 was 2532, checked in by Peter, 10 years ago

prefer <iosfwd> and <ostream>

  • 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 2532 2011-07-31 16:16:25Z peter $
5
6/*
7  Copyright (C) 2004 Peter Johansson
8  Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, 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/statistics/AveragerPair.h"
27
28#include <iosfwd>
29
30namespace theplu {
31namespace yat {
32namespace utility {
33  class VectorBase;
34}
35namespace regression {
36
37  ///
38  /// @brief Interface Class for One Dimensional fitting.   
39  ///
40  /// @see OneDimensionalWeighted.
41  ///
42  class OneDimensional
43  {
44
45  public:
46    ///
47    /// @brief The default constructor
48    ///
49    OneDimensional(void);
50
51    ///
52    /// @brief The destructor
53    ///
54    virtual ~OneDimensional(void);
55 
56    /**
57       @brief Chi-squared
58       
59       Chi-squared is defined as the \f$
60       \sum{(\hat{y_i}-y_i)^2} \f$
61    */
62    double chisq(void) const;
63   
64    /**
65       This function computes the best-fit given a model (see specific
66       class for details) by minimizing \f$ \sum{(\hat{y_i}-y_i)^2}
67       \f$, where \f$ \hat{y} \f$ is the fitted value.
68    */
69    virtual void fit(const utility::VectorBase& x, 
70                     const utility::VectorBase& y)=0; 
71   
72    ///
73    /// @return expected value in @a x accrding to the fitted model
74    ///
75    virtual double predict(const double x) const=0;
76   
77    /**
78       The prediction error is defined as the expected squared
79       deviation a new data point will have from value the model
80       provides: \f$ E(Y|x - \hat{y}(x))^2 \f$ and is typically
81       divided into the conditional variance ( see s2() )
82       given \f$ x \f$ and the squared standard error ( see
83       standard_error2() ) of the model estimation in \f$ x \f$.
84       
85       @return expected squared prediction error for a new data point
86       in @a x
87    */
88    double prediction_error2(const double x) const; 
89
90    ///
91    /// @brief print output to ostream @a os
92    ///
93    /// Printing estimated model to @a os in the points defined by @a
94    /// min, @a max, and @a n. The values printed for each point is
95    /// the x-value, the estimated y-value, and the estimated standard
96    /// deviation of a new data poiunt will have from the y-value
97    /// given the x-value (see prediction_error()).
98    ///
99    /// @param os Ostream printout is sent to
100    /// @param n number of points printed
101    /// @param min smallest x-value for which the model is printed
102    /// @param max largest x-value for which the model is printed
103    ///
104    std::ostream& print(std::ostream& os,const double min, 
105                        double max, const unsigned int n) const;
106
107    /**
108       r2 is defined as \f$ 1 - \frac{Var(Y|x)}{Var(Y)} \f$ or the
109       fraction of the variance explained by the regression model.
110
111       @see s2()
112    */
113    double r2(void) const;
114
115    /**
116       \f$ E(Y|x - E(Y|x))^2 \f$
117
118       @return Conditional variance of Y
119    */
120    virtual double s2(void) const=0;
121
122    /**
123       The standard error is defined as \f$ E(Y|x - \hat{y}(x))^2 \f$
124
125       @return expected squared error of model value in @a x
126    */
127    virtual double standard_error2(const double x) const=0;
128
129  protected:
130    ///
131    /// Variance of y
132    ///
133    double variance(void) const;
134
135    ///
136    /// Averager for pair of x and y
137    ///
138    statistics::AveragerPair ap_;
139
140    ///
141    /// @see chisq()
142    ///
143    double chisq_;
144  };
145
146}}} // of namespaces regression, yat, and theplu
147
148#endif
Note: See TracBrowser for help on using the repository browser.