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