1 | #ifndef _theplu_yat_regression_onedimensioanlweighted_ |
---|
2 | #define _theplu_yat_regression_onedimensioanlweighted_ |
---|
3 | |
---|
4 | // $Id: OneDimensionalWeighted.h 1437 2008-08-25 17:55:00Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005 Peter Johansson |
---|
8 | Copyright (C) 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/AveragerPairWeighted.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 in a weighted |
---|
42 | /// fashion. |
---|
43 | /// |
---|
44 | class OneDimensionalWeighted |
---|
45 | { |
---|
46 | |
---|
47 | public: |
---|
48 | /// |
---|
49 | /// Default Constructor. |
---|
50 | /// |
---|
51 | OneDimensionalWeighted(void); |
---|
52 | |
---|
53 | /// |
---|
54 | /// Destructor |
---|
55 | /// |
---|
56 | virtual ~OneDimensionalWeighted(void); |
---|
57 | |
---|
58 | /** |
---|
59 | This function computes the best-fit given a model (see |
---|
60 | specific class for details) by minimizing \f$ |
---|
61 | \sum{w_i(\hat{y_i}-y_i)^2} \f$, where \f$ \hat{y} \f$ is the |
---|
62 | fitted value. The weight \f$ w_i \f$ should be proportional |
---|
63 | to the inverse of the variance for \f$ y_i \f$ |
---|
64 | */ |
---|
65 | virtual void fit(const utility::VectorBase& x, const utility::VectorBase& y, |
---|
66 | const utility::VectorBase& w)=0; |
---|
67 | |
---|
68 | /// |
---|
69 | /// @return expected value in @a x according to the fitted model |
---|
70 | /// |
---|
71 | virtual double predict(const double x) const=0; |
---|
72 | |
---|
73 | /** |
---|
74 | The prediction error is defined as expected squared deviation a |
---|
75 | new data point (with weight @a w) will be from the model |
---|
76 | value \f$ E((Y|x - \hat{y}(x))^2|w) \f$ and is typically |
---|
77 | divided into the conditional variance ( see s2() ) |
---|
78 | given \f$ x \f$ and the squared standard error ( see |
---|
79 | standard_error2() ) of the model estimation in \f$ x \f$. |
---|
80 | |
---|
81 | \f$ E((Y|x - E(Y|x))^2|w) + E((E(Y|x) - \hat{y}(x))^2) \f$ |
---|
82 | |
---|
83 | @return expected prediction error for a new data point in @a x |
---|
84 | with weight @a w. |
---|
85 | */ |
---|
86 | double prediction_error2(const double x, const double w=1.0) const; |
---|
87 | |
---|
88 | /** |
---|
89 | r2 is defined as \f$ \frac{\sum |
---|
90 | w_i(y_i-\hat{y}_i)^2}{\sum w_i(y_i-m_y)^2} \f$ or the fraction |
---|
91 | of the variance explained by the regression model. |
---|
92 | */ |
---|
93 | double r2(void) const; |
---|
94 | |
---|
95 | /** |
---|
96 | \f$ s^2 \f$ is the estimation of variance of residuals or |
---|
97 | equivalently the conditional variance of Y. |
---|
98 | |
---|
99 | @return Conditional variance of Y |
---|
100 | */ |
---|
101 | virtual double s2(double w=1) const=0; |
---|
102 | |
---|
103 | /** |
---|
104 | The standard error is defined as \f$ E((Y|x,w - |
---|
105 | \hat{y}(x))^2) \f$ |
---|
106 | |
---|
107 | @return error of model value in @a x |
---|
108 | */ |
---|
109 | virtual double standard_error2(const double x) const=0; |
---|
110 | |
---|
111 | protected: |
---|
112 | /// |
---|
113 | /// Averager for pair of x and y |
---|
114 | /// |
---|
115 | statistics::AveragerPairWeighted ap_; |
---|
116 | |
---|
117 | /** |
---|
118 | @brief Chi-squared |
---|
119 | |
---|
120 | Chi-squared is defined as the \f$ |
---|
121 | \sum{w_i(\hat{y_i}-y_i)^2} \f$ |
---|
122 | */ |
---|
123 | double chisq_; |
---|
124 | |
---|
125 | private: |
---|
126 | }; |
---|
127 | |
---|
128 | }}} // of namespaces regression, yat, and theplu |
---|
129 | |
---|
130 | #endif |
---|