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