1 | #ifndef _theplu_yat_regression_onedimensional_ |
---|
2 | #define _theplu_yat_regression_onedimensional_ |
---|
3 | |
---|
4 | // $Id: OneDimensional.h 1000 2007-12-23 20:09:15Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson |
---|
9 | Copyright (C) 2007 Peter Johansson |
---|
10 | |
---|
11 | This file is part of the yat library, http://trac.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 vector; |
---|
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::vector& x, const utility::vector& y)=0; |
---|
73 | |
---|
74 | /// |
---|
75 | /// @return expected value in @a x accrding to the fitted model |
---|
76 | /// |
---|
77 | virtual double predict(const double x) const=0; |
---|
78 | |
---|
79 | /** |
---|
80 | The prediction error is defined as the expected squared |
---|
81 | deviation a new data point will have from value the model |
---|
82 | provides: \f$ E(Y|x - \hat{y}(x))^2 \f$ and is typically |
---|
83 | divided into the conditional variance ( see s2() ) |
---|
84 | given \f$ x \f$ and the squared standard error ( see |
---|
85 | standard_error2() ) of the model estimation in \f$ x \f$. |
---|
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 | r2 is defined as \f$ 1 - \frac{Var(Y|x)}{Var(Y)} \f$ or the |
---|
111 | fraction of the variance explained by the regression model. |
---|
112 | |
---|
113 | @see s2() |
---|
114 | */ |
---|
115 | double r2(void) const; |
---|
116 | |
---|
117 | /** |
---|
118 | \f$ E(Y|x - E(Y|x))^2 \f$ |
---|
119 | |
---|
120 | @return Conditional variance of Y |
---|
121 | */ |
---|
122 | virtual double s2(void) const=0; |
---|
123 | |
---|
124 | /** |
---|
125 | The standard error is defined as \f$ E(Y|x - \hat{y}(x))^2 \f$ |
---|
126 | |
---|
127 | @return expected squared error of model value in @a x |
---|
128 | */ |
---|
129 | virtual double standard_error2(const double x) const=0; |
---|
130 | |
---|
131 | protected: |
---|
132 | /// |
---|
133 | /// Variance of y |
---|
134 | /// |
---|
135 | double variance(void) const; |
---|
136 | |
---|
137 | /// |
---|
138 | /// Averager for pair of x and y |
---|
139 | /// |
---|
140 | statistics::AveragerPair ap_; |
---|
141 | |
---|
142 | /// |
---|
143 | /// @see chisq() |
---|
144 | /// |
---|
145 | double chisq_; |
---|
146 | }; |
---|
147 | |
---|
148 | }}} // of namespaces regression, yat, and theplu |
---|
149 | |
---|
150 | #endif |
---|