681 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_regression_naive_ |
681 |
11 Oct 06 |
jari |
2 |
#define _theplu_yat_regression_naive_ |
202 |
01 Nov 04 |
peter |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
616 |
31 Aug 06 |
jari |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
831 |
27 Mar 07 |
peter |
Copyright (C) 2004 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
295 |
29 Apr 05 |
peter |
11 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
13 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
18 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
23 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
26 |
*/ |
675 |
10 Oct 06 |
jari |
27 |
|
680 |
11 Oct 06 |
jari |
28 |
#include "OneDimensional.h" |
675 |
10 Oct 06 |
jari |
29 |
|
216 |
29 Dec 04 |
peter |
30 |
#include <utility> |
202 |
01 Nov 04 |
peter |
31 |
|
383 |
12 Aug 05 |
jari |
32 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
33 |
namespace yat { |
616 |
31 Aug 06 |
jari |
34 |
namespace utility { |
1019 |
01 Feb 08 |
peter |
35 |
class VectorBase; |
616 |
31 Aug 06 |
jari |
36 |
} |
383 |
12 Aug 05 |
jari |
37 |
namespace regression { |
235 |
21 Feb 05 |
peter |
38 |
|
713 |
21 Dec 06 |
peter |
39 |
/** |
713 |
21 Dec 06 |
peter |
@brief Naive Regression |
713 |
21 Dec 06 |
peter |
41 |
|
4200 |
19 Aug 22 |
peter |
Data are modeled as \f$ y_i = \alpha + \epsilon_i \f$ |
4200 |
19 Aug 22 |
peter |
43 |
|
4200 |
19 Aug 22 |
peter |
44 |
*/ |
4200 |
19 Aug 22 |
peter |
45 |
class Naive : public OneDimensional |
202 |
01 Nov 04 |
peter |
46 |
{ |
4200 |
19 Aug 22 |
peter |
47 |
|
202 |
01 Nov 04 |
peter |
48 |
public: |
202 |
01 Nov 04 |
peter |
49 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The default constructor |
202 |
01 Nov 04 |
peter |
51 |
/// |
703 |
18 Dec 06 |
jari |
52 |
Naive(void); |
202 |
01 Nov 04 |
peter |
53 |
|
202 |
01 Nov 04 |
peter |
54 |
/// |
4200 |
19 Aug 22 |
peter |
/// @brief The destructor |
202 |
01 Nov 04 |
peter |
56 |
/// |
703 |
18 Dec 06 |
jari |
57 |
virtual ~Naive(void); |
4200 |
19 Aug 22 |
peter |
58 |
|
202 |
01 Nov 04 |
peter |
59 |
/// |
235 |
21 Feb 05 |
peter |
/// This function computes the best-fit for the naive model \f$ y |
235 |
21 Feb 05 |
peter |
/// = m \f$ from vectors \a x and \a y, by minimizing \f$ |
4200 |
19 Aug 22 |
peter |
/// \sum{(y_i-m)^2} \f$. |
202 |
01 Nov 04 |
peter |
63 |
/// |
1019 |
01 Feb 08 |
peter |
64 |
void fit(const utility::VectorBase& x, const utility::VectorBase& y); |
202 |
01 Nov 04 |
peter |
65 |
|
202 |
01 Nov 04 |
peter |
66 |
/// |
4200 |
19 Aug 22 |
peter |
/// The predicted value is the average \f$ m \f$ |
702 |
26 Oct 06 |
peter |
68 |
/// |
586 |
19 Jun 06 |
peter |
69 |
double predict(const double x) const; |
4200 |
19 Aug 22 |
peter |
70 |
|
728 |
04 Jan 07 |
peter |
71 |
/** |
728 |
04 Jan 07 |
peter |
\f$ \frac{\sum \epsilon_i^2}{N-1} \f$ |
728 |
04 Jan 07 |
peter |
73 |
|
729 |
05 Jan 07 |
peter |
@return Conditional variance |
728 |
04 Jan 07 |
peter |
75 |
*/ |
728 |
04 Jan 07 |
peter |
76 |
double s2(void) const; |
728 |
04 Jan 07 |
peter |
77 |
|
221 |
30 Dec 04 |
peter |
78 |
/// |
729 |
05 Jan 07 |
peter |
/// \f$ \frac{s^2}{N} \f$ |
221 |
30 Dec 04 |
peter |
80 |
/// |
729 |
05 Jan 07 |
peter |
/// @return squared standard error |
729 |
05 Jan 07 |
peter |
82 |
/// |
713 |
21 Dec 06 |
peter |
/// @see statistics::Averager |
713 |
21 Dec 06 |
peter |
84 |
/// |
727 |
04 Jan 07 |
peter |
85 |
double standard_error2(const double x) const; |
586 |
19 Jun 06 |
peter |
86 |
|
202 |
01 Nov 04 |
peter |
87 |
private: |
703 |
18 Dec 06 |
jari |
88 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The copy constructor (not implemented). |
703 |
18 Dec 06 |
jari |
90 |
/// |
703 |
18 Dec 06 |
jari |
91 |
Naive(const Naive&); |
703 |
18 Dec 06 |
jari |
92 |
|
702 |
26 Oct 06 |
peter |
93 |
double mse_; |
202 |
01 Nov 04 |
peter |
94 |
}; |
202 |
01 Nov 04 |
peter |
95 |
|
681 |
11 Oct 06 |
jari |
96 |
}}} // of namespaces regression, yat, and theplu |
202 |
01 Nov 04 |
peter |
97 |
|
202 |
01 Nov 04 |
peter |
98 |
#endif |