1 | #ifndef _theplu_yat_regression_naiveweighted_ |
---|
2 | #define _theplu_yat_regression_naiveweighted_ |
---|
3 | |
---|
4 | // $Id: NaiveWeighted.h 1392 2008-07-28 19:35:30Z 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 "OneDimensionalWeighted.h" |
---|
30 | |
---|
31 | #include <cmath> |
---|
32 | #include <iostream> |
---|
33 | #include <utility> |
---|
34 | |
---|
35 | namespace theplu { |
---|
36 | namespace yat { |
---|
37 | namespace utility { |
---|
38 | class VectorBase; |
---|
39 | } |
---|
40 | namespace regression { |
---|
41 | |
---|
42 | /// |
---|
43 | /// @brief naive fitting. |
---|
44 | /// |
---|
45 | /// @todo document |
---|
46 | /// |
---|
47 | class NaiveWeighted : public OneDimensionalWeighted |
---|
48 | { |
---|
49 | |
---|
50 | public: |
---|
51 | /// |
---|
52 | /// @brief The default constructor |
---|
53 | /// |
---|
54 | NaiveWeighted(void); |
---|
55 | |
---|
56 | /// |
---|
57 | /// @brief The destructor |
---|
58 | /// |
---|
59 | virtual ~NaiveWeighted(void); |
---|
60 | |
---|
61 | /** |
---|
62 | This function computes the best-fit for the naive model \f$ y |
---|
63 | = m \f$ from vectors \a x and \a y, by minimizing \f$ \sum |
---|
64 | w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to |
---|
65 | the inverse of the variance for \f$ y_i \f$ |
---|
66 | */ |
---|
67 | void fit(const utility::VectorBase& x, |
---|
68 | const utility::VectorBase& y, |
---|
69 | const utility::VectorBase& w); |
---|
70 | |
---|
71 | /// |
---|
72 | /// Function predicting value using the naive model, i.e. a |
---|
73 | /// weighted average. |
---|
74 | /// |
---|
75 | double predict(const double x) const; |
---|
76 | |
---|
77 | /** |
---|
78 | \f$ \frac{\sum w_i\epsilon_i^2}{ w \left(\frac{\left(\sum |
---|
79 | w_i\right)^2}{\sum w_i^2}-1\right)} \f$ |
---|
80 | |
---|
81 | Rescaling all weights, both in fit and the passed @a w, results |
---|
82 | in the same returned value. |
---|
83 | |
---|
84 | @return Conditional variance of Y with weight @a w. |
---|
85 | */ |
---|
86 | double s2(const double w=1) const; |
---|
87 | |
---|
88 | /** |
---|
89 | \f$ \frac{\sum w_i\epsilon_i^2}{ \left(\frac{\left(\sum |
---|
90 | w_i\right)^2}{\sum w_i^2}-1\right)\sum w_i} \f$ |
---|
91 | |
---|
92 | @return estimated squared error of model value in @a x |
---|
93 | */ |
---|
94 | double standard_error2(const double x) const; |
---|
95 | |
---|
96 | private: |
---|
97 | /// |
---|
98 | /// Copy Constructor. (not implemented) |
---|
99 | /// |
---|
100 | NaiveWeighted(const NaiveWeighted&); |
---|
101 | |
---|
102 | }; |
---|
103 | |
---|
104 | }}} // of namespaces regression, yat, and theplu |
---|
105 | |
---|
106 | #endif |
---|