1 | #ifndef _theplu_yat_regression_naiveweighted_ |
---|
2 | #define _theplu_yat_regression_naiveweighted_ |
---|
3 | |
---|
4 | // $Id: NaiveWeighted.h 703 2006-12-18 00:47:44Z jari $ |
---|
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 "OneDimensionalWeighted.h" |
---|
28 | |
---|
29 | #include <cmath> |
---|
30 | #include <iostream> |
---|
31 | #include <utility> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace utility { |
---|
36 | class vector; |
---|
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::vector& x, |
---|
66 | const utility::vector& y, |
---|
67 | const utility::vector& w); |
---|
68 | |
---|
69 | /// |
---|
70 | /// Function predicting value using the naive model, i.e. a |
---|
71 | /// weighted average. |
---|
72 | /// |
---|
73 | inline double predict(const double x) const |
---|
74 | { return ap_.y_averager().mean(); } |
---|
75 | |
---|
76 | /// |
---|
77 | /// @brief For a naive model mse is identical to standard deviation |
---|
78 | /// |
---|
79 | /// @see AveragerWeighted |
---|
80 | /// |
---|
81 | inline double mse(void) const { return ap_.y_averager().std(); } |
---|
82 | |
---|
83 | /// |
---|
84 | /// @return estimation of error of model value in @a x |
---|
85 | /// |
---|
86 | inline double standard_error(const double x) const |
---|
87 | { return ap_.y_averager().standard_error(); } |
---|
88 | |
---|
89 | private: |
---|
90 | /// |
---|
91 | /// Copy Constructor. (not implemented) |
---|
92 | /// |
---|
93 | NaiveWeighted(const NaiveWeighted&); |
---|
94 | |
---|
95 | }; |
---|
96 | |
---|
97 | }}} // of namespaces regression, yat, and theplu |
---|
98 | |
---|
99 | #endif |
---|