429 |
08 Dec 05 |
peter |
// $Id$ |
429 |
08 Dec 05 |
peter |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
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 |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2012 Peter Johansson |
429 |
08 Dec 05 |
peter |
9 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
429 |
08 Dec 05 |
peter |
11 |
|
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. |
429 |
08 Dec 05 |
peter |
16 |
|
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 |
21 |
|
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 |
24 |
*/ |
675 |
10 Oct 06 |
jari |
25 |
|
2881 |
18 Nov 12 |
peter |
26 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
27 |
|
680 |
11 Oct 06 |
jari |
28 |
#include "NaiveWeighted.h" |
680 |
11 Oct 06 |
jari |
29 |
#include "OneDimensional.h" |
682 |
11 Oct 06 |
jari |
30 |
#include "yat/statistics/AveragerWeighted.h" |
1120 |
21 Feb 08 |
peter |
31 |
#include "yat/utility/Vector.h" |
675 |
10 Oct 06 |
jari |
32 |
|
702 |
26 Oct 06 |
peter |
33 |
#include <cassert> |
702 |
26 Oct 06 |
peter |
34 |
|
429 |
08 Dec 05 |
peter |
35 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
36 |
namespace yat { |
429 |
08 Dec 05 |
peter |
37 |
namespace regression { |
429 |
08 Dec 05 |
peter |
38 |
|
703 |
18 Dec 06 |
jari |
39 |
NaiveWeighted::NaiveWeighted(void) |
703 |
18 Dec 06 |
jari |
40 |
: OneDimensionalWeighted() |
703 |
18 Dec 06 |
jari |
41 |
{ |
703 |
18 Dec 06 |
jari |
42 |
} |
703 |
18 Dec 06 |
jari |
43 |
|
703 |
18 Dec 06 |
jari |
44 |
NaiveWeighted::~NaiveWeighted(void) |
703 |
18 Dec 06 |
jari |
45 |
{ |
703 |
18 Dec 06 |
jari |
46 |
} |
703 |
18 Dec 06 |
jari |
47 |
|
1020 |
01 Feb 08 |
peter |
48 |
void NaiveWeighted::fit(const utility::VectorBase& x, |
1020 |
01 Feb 08 |
peter |
49 |
const utility::VectorBase& y, |
1020 |
01 Feb 08 |
peter |
50 |
const utility::VectorBase& w) |
429 |
08 Dec 05 |
peter |
51 |
{ |
702 |
26 Oct 06 |
peter |
52 |
assert(x.size()==y.size()); |
702 |
26 Oct 06 |
peter |
53 |
assert(y.size()==w.size()); |
702 |
26 Oct 06 |
peter |
54 |
ap_.reset(); |
1120 |
21 Feb 08 |
peter |
55 |
utility::Vector dummy(x.size(),1.0); |
1043 |
06 Feb 08 |
peter |
56 |
add(ap_, x.begin(), x.end(), y.begin(),dummy.begin(), w.begin()); |
729 |
05 Jan 07 |
peter |
57 |
chisq_ = ap_.y_averager().sum_xx_centered(); |
429 |
08 Dec 05 |
peter |
58 |
} |
429 |
08 Dec 05 |
peter |
59 |
|
729 |
05 Jan 07 |
peter |
60 |
|
718 |
26 Dec 06 |
jari |
61 |
double NaiveWeighted::predict(const double x) const |
718 |
26 Dec 06 |
jari |
62 |
{ |
718 |
26 Dec 06 |
jari |
63 |
return ap_.y_averager().mean(); |
718 |
26 Dec 06 |
jari |
64 |
} |
718 |
26 Dec 06 |
jari |
65 |
|
729 |
05 Jan 07 |
peter |
66 |
|
729 |
05 Jan 07 |
peter |
67 |
double NaiveWeighted::s2(double w) const |
718 |
26 Dec 06 |
jari |
68 |
{ |
729 |
05 Jan 07 |
peter |
69 |
return chisq_/(w*(ap_.y_averager().n()-1)); |
718 |
26 Dec 06 |
jari |
70 |
} |
718 |
26 Dec 06 |
jari |
71 |
|
729 |
05 Jan 07 |
peter |
72 |
|
729 |
05 Jan 07 |
peter |
73 |
double NaiveWeighted::standard_error2(const double x) const |
4200 |
19 Aug 22 |
peter |
74 |
{ |
730 |
06 Jan 07 |
peter |
75 |
return chisq_/( (ap_.y_averager().n()-1)*ap_.y_averager().sum_w() ); |
718 |
26 Dec 06 |
jari |
76 |
} |
718 |
26 Dec 06 |
jari |
77 |
|
681 |
11 Oct 06 |
jari |
78 |
}}} // of namespaces regression, yat, and theplu |