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