1 | #ifndef _theplu_yat_regression_naive_ |
---|
2 | #define _theplu_yat_regression_naive_ |
---|
3 | |
---|
4 | // $Id: Naive.h 1486 2008-09-09 21:17:19Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 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 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 "OneDimensional.h" |
---|
30 | |
---|
31 | #include <iostream> |
---|
32 | #include <utility> |
---|
33 | |
---|
34 | namespace theplu { |
---|
35 | namespace yat { |
---|
36 | namespace utility { |
---|
37 | class VectorBase; |
---|
38 | } |
---|
39 | namespace regression { |
---|
40 | |
---|
41 | /** |
---|
42 | @brief Naive Regression |
---|
43 | |
---|
44 | Data are modeled as \f$ y_i = \alpha + \epsilon_i \f$ |
---|
45 | |
---|
46 | */ |
---|
47 | class Naive : public OneDimensional |
---|
48 | { |
---|
49 | |
---|
50 | public: |
---|
51 | /// |
---|
52 | /// @brief The default constructor |
---|
53 | /// |
---|
54 | Naive(void); |
---|
55 | |
---|
56 | /// |
---|
57 | /// @brief The destructor |
---|
58 | /// |
---|
59 | virtual ~Naive(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$ |
---|
64 | /// \sum{(y_i-m)^2} \f$. |
---|
65 | /// |
---|
66 | void fit(const utility::VectorBase& x, const utility::VectorBase& y); |
---|
67 | |
---|
68 | /// |
---|
69 | /// The predicted value is the average \f$ m \f$ |
---|
70 | /// |
---|
71 | double predict(const double x) const; |
---|
72 | |
---|
73 | /** |
---|
74 | \f$ \frac{\sum \epsilon_i^2}{N-1} \f$ |
---|
75 | |
---|
76 | @return Conditional variance |
---|
77 | */ |
---|
78 | double s2(void) const; |
---|
79 | |
---|
80 | /// |
---|
81 | /// \f$ \frac{s^2}{N} \f$ |
---|
82 | /// |
---|
83 | /// @return squared standard error |
---|
84 | /// |
---|
85 | /// @see statistics::Averager |
---|
86 | /// |
---|
87 | double standard_error2(const double x) const; |
---|
88 | |
---|
89 | private: |
---|
90 | /// |
---|
91 | /// @brief The copy constructor (not implemented). |
---|
92 | /// |
---|
93 | Naive(const Naive&); |
---|
94 | |
---|
95 | double mse_; |
---|
96 | }; |
---|
97 | |
---|
98 | }}} // of namespaces regression, yat, and theplu |
---|
99 | |
---|
100 | #endif |
---|