1 | #ifndef _theplu_yat_regression_naive_ |
---|
2 | #define _theplu_yat_regression_naive_ |
---|
3 | |
---|
4 | // $Id: Naive.h 2119 2009-12-12 23:11:43Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 3 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
24 | */ |
---|
25 | |
---|
26 | #include "OneDimensional.h" |
---|
27 | |
---|
28 | #include <utility> |
---|
29 | |
---|
30 | namespace theplu { |
---|
31 | namespace yat { |
---|
32 | namespace utility { |
---|
33 | class VectorBase; |
---|
34 | } |
---|
35 | namespace regression { |
---|
36 | |
---|
37 | /** |
---|
38 | @brief Naive Regression |
---|
39 | |
---|
40 | Data are modeled as \f$ y_i = \alpha + \epsilon_i \f$ |
---|
41 | |
---|
42 | */ |
---|
43 | class Naive : public OneDimensional |
---|
44 | { |
---|
45 | |
---|
46 | public: |
---|
47 | /// |
---|
48 | /// @brief The default constructor |
---|
49 | /// |
---|
50 | Naive(void); |
---|
51 | |
---|
52 | /// |
---|
53 | /// @brief The destructor |
---|
54 | /// |
---|
55 | virtual ~Naive(void); |
---|
56 | |
---|
57 | /// |
---|
58 | /// This function computes the best-fit for the naive model \f$ y |
---|
59 | /// = m \f$ from vectors \a x and \a y, by minimizing \f$ |
---|
60 | /// \sum{(y_i-m)^2} \f$. |
---|
61 | /// |
---|
62 | void fit(const utility::VectorBase& x, const utility::VectorBase& y); |
---|
63 | |
---|
64 | /// |
---|
65 | /// The predicted value is the average \f$ m \f$ |
---|
66 | /// |
---|
67 | double predict(const double x) const; |
---|
68 | |
---|
69 | /** |
---|
70 | \f$ \frac{\sum \epsilon_i^2}{N-1} \f$ |
---|
71 | |
---|
72 | @return Conditional variance |
---|
73 | */ |
---|
74 | double s2(void) const; |
---|
75 | |
---|
76 | /// |
---|
77 | /// \f$ \frac{s^2}{N} \f$ |
---|
78 | /// |
---|
79 | /// @return squared standard error |
---|
80 | /// |
---|
81 | /// @see statistics::Averager |
---|
82 | /// |
---|
83 | double standard_error2(const double x) const; |
---|
84 | |
---|
85 | private: |
---|
86 | /// |
---|
87 | /// @brief The copy constructor (not implemented). |
---|
88 | /// |
---|
89 | Naive(const Naive&); |
---|
90 | |
---|
91 | double mse_; |
---|
92 | }; |
---|
93 | |
---|
94 | }}} // of namespaces regression, yat, and theplu |
---|
95 | |
---|
96 | #endif |
---|