1 | #ifndef _theplu_yat_regression_onedimensional_ |
---|
2 | #define _theplu_yat_regression_onedimensional_ |
---|
3 | |
---|
4 | // $Id: OneDimensional.h 727 2007-01-04 15:06:14Z 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 "yat/statistics/AveragerPair.h" |
---|
28 | |
---|
29 | #include <ostream> |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace utility { |
---|
34 | class vector; |
---|
35 | } |
---|
36 | namespace regression { |
---|
37 | |
---|
38 | /// |
---|
39 | /// Abstract Base 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$ \frac |
---|
61 | {\sum{(\hat{y_i}-y_i)^2}}{1} \f$ |
---|
62 | */ |
---|
63 | virtual double chisq(void) const=0; |
---|
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::vector& x, const utility::vector& 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 two terms \f$ E(Y|x - E(Y|x))^2 \f$ and \f$ |
---|
82 | E(E(Y|x) - \hat{y}(x))^2 \f$, which is the conditional variance |
---|
83 | given \f$ x \f$ and the squared standard error (see |
---|
84 | standard_error2()) of the model estimation in \f$ x \f$, |
---|
85 | respectively. |
---|
86 | |
---|
87 | @return expected squared prediction error for a new data point |
---|
88 | in @a x |
---|
89 | */ |
---|
90 | double prediction_error2(const double x) const; |
---|
91 | |
---|
92 | /// |
---|
93 | /// @brief print output to ostream @a os |
---|
94 | /// |
---|
95 | /// Printing estimated model to @a os in the points defined by @a |
---|
96 | /// min, @a max, and @a n. The values printed for each point is |
---|
97 | /// the x-value, the estimated y-value, and the estimated standard |
---|
98 | /// deviation of a new data poiunt will have from the y-value |
---|
99 | /// given the x-value (see prediction_error()). |
---|
100 | /// |
---|
101 | /// @param os Ostream printout is sent to |
---|
102 | /// @param n number of points printed |
---|
103 | /// @param min smallest x-value for which the model is printed |
---|
104 | /// @param max largest x-value for which the model is printed |
---|
105 | /// |
---|
106 | std::ostream& print(std::ostream& os,const double min, |
---|
107 | double max, const u_int n) const; |
---|
108 | |
---|
109 | /** |
---|
110 | r-squared is defined as \f$ \frac{Var(Y|x)}{Var(Y)} \f$ or the |
---|
111 | fraction of the variance explained by the regression model. |
---|
112 | */ |
---|
113 | double r_squared(void) const; |
---|
114 | |
---|
115 | /** |
---|
116 | The standard error is defined as \f$ E(Y|x - \hat{y}(x))^2 \f$ |
---|
117 | |
---|
118 | @return expected squared error of model value in @a x |
---|
119 | */ |
---|
120 | virtual double standard_error2(const double x) const=0; |
---|
121 | |
---|
122 | protected: |
---|
123 | /// |
---|
124 | /// Variance of y |
---|
125 | /// |
---|
126 | double variance(void) const; |
---|
127 | |
---|
128 | /// |
---|
129 | /// Averager for pair of x and y |
---|
130 | /// |
---|
131 | statistics::AveragerPair ap_; |
---|
132 | |
---|
133 | }; |
---|
134 | |
---|
135 | }}} // of namespaces regression, yat, and theplu |
---|
136 | |
---|
137 | #endif |
---|