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) 2011, 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 |
675 |
10 Oct 06 |
jari |
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. |
675 |
10 Oct 06 |
jari |
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 "OneDimensional.h" |
675 |
10 Oct 06 |
jari |
29 |
|
2532 |
31 Jul 11 |
peter |
30 |
#include <ostream> |
2532 |
31 Jul 11 |
peter |
31 |
|
429 |
08 Dec 05 |
peter |
32 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
33 |
namespace yat { |
429 |
08 Dec 05 |
peter |
34 |
namespace regression { |
429 |
08 Dec 05 |
peter |
35 |
|
703 |
18 Dec 06 |
jari |
36 |
OneDimensional::OneDimensional(void) |
729 |
05 Jan 07 |
peter |
37 |
: chisq_(0) |
703 |
18 Dec 06 |
jari |
38 |
{ |
703 |
18 Dec 06 |
jari |
39 |
} |
703 |
18 Dec 06 |
jari |
40 |
|
703 |
18 Dec 06 |
jari |
41 |
OneDimensional::~OneDimensional(void) |
703 |
18 Dec 06 |
jari |
42 |
{ |
703 |
18 Dec 06 |
jari |
43 |
} |
703 |
18 Dec 06 |
jari |
44 |
|
713 |
21 Dec 06 |
peter |
45 |
|
729 |
05 Jan 07 |
peter |
46 |
double OneDimensional::chisq(void) const |
729 |
05 Jan 07 |
peter |
47 |
{ |
729 |
05 Jan 07 |
peter |
48 |
return chisq_; |
729 |
05 Jan 07 |
peter |
49 |
} |
729 |
05 Jan 07 |
peter |
50 |
|
729 |
05 Jan 07 |
peter |
51 |
|
4200 |
19 Aug 22 |
peter |
52 |
double OneDimensional::prediction_error2(const double x) const |
4200 |
19 Aug 22 |
peter |
53 |
{ |
4200 |
19 Aug 22 |
peter |
54 |
return s2()+standard_error2(x); |
713 |
21 Dec 06 |
peter |
55 |
} |
713 |
21 Dec 06 |
peter |
56 |
|
713 |
21 Dec 06 |
peter |
57 |
|
4200 |
19 Aug 22 |
peter |
58 |
std::ostream& OneDimensional::print(std::ostream& os, const double min, |
1271 |
09 Apr 08 |
peter |
59 |
double max, const unsigned int n) const |
429 |
08 Dec 05 |
peter |
60 |
{ |
429 |
08 Dec 05 |
peter |
61 |
double dx; |
429 |
08 Dec 05 |
peter |
62 |
if (n>1) |
429 |
08 Dec 05 |
peter |
63 |
dx=(max-min)/(n-1); |
429 |
08 Dec 05 |
peter |
64 |
else{ |
429 |
08 Dec 05 |
peter |
65 |
dx=1.0; |
429 |
08 Dec 05 |
peter |
66 |
max=min; |
429 |
08 Dec 05 |
peter |
67 |
} |
429 |
08 Dec 05 |
peter |
68 |
|
429 |
08 Dec 05 |
peter |
69 |
for ( double x=min; x<=max; x+=dx) { |
586 |
19 Jun 06 |
peter |
70 |
double y = predict(x); |
727 |
04 Jan 07 |
peter |
71 |
double y_err = sqrt(prediction_error2(x)); |
429 |
08 Dec 05 |
peter |
72 |
os << x << "\t" << y << "\t" << y_err << "\n"; |
429 |
08 Dec 05 |
peter |
73 |
} |
429 |
08 Dec 05 |
peter |
74 |
return os; |
429 |
08 Dec 05 |
peter |
75 |
} |
429 |
08 Dec 05 |
peter |
76 |
|
718 |
26 Dec 06 |
jari |
77 |
|
729 |
05 Jan 07 |
peter |
78 |
double OneDimensional::r2(void) const |
718 |
26 Dec 06 |
jari |
79 |
{ |
729 |
05 Jan 07 |
peter |
80 |
return 1 - chisq()/ap_.y_averager().sum_xx_centered(); |
718 |
26 Dec 06 |
jari |
81 |
} |
718 |
26 Dec 06 |
jari |
82 |
|
718 |
26 Dec 06 |
jari |
83 |
double OneDimensional::variance(void) const |
718 |
26 Dec 06 |
jari |
84 |
{ |
718 |
26 Dec 06 |
jari |
85 |
return ap_.y_averager().variance(); |
718 |
26 Dec 06 |
jari |
86 |
} |
718 |
26 Dec 06 |
jari |
87 |
|
681 |
11 Oct 06 |
jari |
88 |
}}} // of namespaces regression, yat, and theplu |