681 |
11 Oct 06 |
jari |
1 |
#ifndef _theplu_yat_regression_naiveweighted_ |
681 |
11 Oct 06 |
jari |
2 |
#define _theplu_yat_regression_naiveweighted_ |
429 |
08 Dec 05 |
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) 2005 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 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 |
429 |
08 Dec 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 "OneDimensionalWeighted.h" |
675 |
10 Oct 06 |
jari |
29 |
|
586 |
19 Jun 06 |
peter |
30 |
#include <cmath> |
429 |
08 Dec 05 |
peter |
31 |
#include <utility> |
429 |
08 Dec 05 |
peter |
32 |
|
429 |
08 Dec 05 |
peter |
33 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
34 |
namespace yat { |
616 |
31 Aug 06 |
jari |
35 |
namespace utility { |
1020 |
01 Feb 08 |
peter |
36 |
class VectorBase; |
616 |
31 Aug 06 |
jari |
37 |
} |
429 |
08 Dec 05 |
peter |
38 |
namespace regression { |
429 |
08 Dec 05 |
peter |
39 |
|
429 |
08 Dec 05 |
peter |
40 |
/// |
429 |
08 Dec 05 |
peter |
/// @brief naive fitting. |
429 |
08 Dec 05 |
peter |
42 |
/// |
2842 |
17 Sep 12 |
peter |
43 |
class NaiveWeighted : public OneDimensionalWeighted |
429 |
08 Dec 05 |
peter |
44 |
{ |
2842 |
17 Sep 12 |
peter |
45 |
|
429 |
08 Dec 05 |
peter |
46 |
public: |
429 |
08 Dec 05 |
peter |
47 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The default constructor |
429 |
08 Dec 05 |
peter |
49 |
/// |
703 |
18 Dec 06 |
jari |
50 |
NaiveWeighted(void); |
429 |
08 Dec 05 |
peter |
51 |
|
429 |
08 Dec 05 |
peter |
52 |
/// |
703 |
18 Dec 06 |
jari |
/// @brief The destructor |
429 |
08 Dec 05 |
peter |
54 |
/// |
703 |
18 Dec 06 |
jari |
55 |
virtual ~NaiveWeighted(void); |
2842 |
17 Sep 12 |
peter |
56 |
|
702 |
26 Oct 06 |
peter |
57 |
/** |
702 |
26 Oct 06 |
peter |
This function computes the best-fit for the naive model \f$ y |
702 |
26 Oct 06 |
peter |
= m \f$ from vectors \a x and \a y, by minimizing \f$ \sum |
702 |
26 Oct 06 |
peter |
w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to |
702 |
26 Oct 06 |
peter |
the inverse of the variance for \f$ y_i \f$ |
702 |
26 Oct 06 |
peter |
62 |
*/ |
1020 |
01 Feb 08 |
peter |
63 |
void fit(const utility::VectorBase& x, |
1020 |
01 Feb 08 |
peter |
64 |
const utility::VectorBase& y, |
1020 |
01 Feb 08 |
peter |
65 |
const utility::VectorBase& w); |
429 |
08 Dec 05 |
peter |
66 |
|
429 |
08 Dec 05 |
peter |
67 |
/// |
495 |
11 Jan 06 |
peter |
/// Function predicting value using the naive model, i.e. a |
2842 |
17 Sep 12 |
peter |
/// weighted average. |
429 |
08 Dec 05 |
peter |
70 |
/// |
718 |
26 Dec 06 |
jari |
71 |
double predict(const double x) const; |
429 |
08 Dec 05 |
peter |
72 |
|
729 |
05 Jan 07 |
peter |
73 |
/** |
729 |
05 Jan 07 |
peter |
\f$ \frac{\sum w_i\epsilon_i^2}{ w \left(\frac{\left(\sum |
729 |
05 Jan 07 |
peter |
w_i\right)^2}{\sum w_i^2}-1\right)} \f$ |
586 |
19 Jun 06 |
peter |
76 |
|
729 |
05 Jan 07 |
peter |
Rescaling all weights, both in fit and the passed @a w, results |
729 |
05 Jan 07 |
peter |
in the same returned value. |
586 |
19 Jun 06 |
peter |
79 |
|
729 |
05 Jan 07 |
peter |
@return Conditional variance of Y with weight @a w. |
729 |
05 Jan 07 |
peter |
81 |
*/ |
729 |
05 Jan 07 |
peter |
82 |
double s2(const double w=1) const; |
729 |
05 Jan 07 |
peter |
83 |
|
729 |
05 Jan 07 |
peter |
84 |
/** |
729 |
05 Jan 07 |
peter |
\f$ \frac{\sum w_i\epsilon_i^2}{ \left(\frac{\left(\sum |
729 |
05 Jan 07 |
peter |
w_i\right)^2}{\sum w_i^2}-1\right)\sum w_i} \f$ |
729 |
05 Jan 07 |
peter |
87 |
|
729 |
05 Jan 07 |
peter |
@return estimated squared error of model value in @a x |
729 |
05 Jan 07 |
peter |
89 |
*/ |
729 |
05 Jan 07 |
peter |
90 |
double standard_error2(const double x) const; |
729 |
05 Jan 07 |
peter |
91 |
|
429 |
08 Dec 05 |
peter |
92 |
private: |
429 |
08 Dec 05 |
peter |
93 |
/// |
429 |
08 Dec 05 |
peter |
/// Copy Constructor. (not implemented) |
429 |
08 Dec 05 |
peter |
95 |
/// |
429 |
08 Dec 05 |
peter |
96 |
NaiveWeighted(const NaiveWeighted&); |
429 |
08 Dec 05 |
peter |
97 |
|
429 |
08 Dec 05 |
peter |
98 |
}; |
429 |
08 Dec 05 |
peter |
99 |
|
681 |
11 Oct 06 |
jari |
100 |
}}} // of namespaces regression, yat, and theplu |
429 |
08 Dec 05 |
peter |
101 |
|
429 |
08 Dec 05 |
peter |
102 |
#endif |