1 | // $Id: OneDimensional.cc 1392 2008-07-28 19:35:30Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2005 Peter Johansson |
---|
5 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
6 | Copyright (C) 2008 Peter Johansson |
---|
7 | |
---|
8 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
9 | |
---|
10 | The yat library is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License as |
---|
12 | published by the Free Software Foundation; either version 2 of the |
---|
13 | License, or (at your option) any later version. |
---|
14 | |
---|
15 | The yat library is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with this program; if not, write to the Free Software |
---|
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
23 | 02111-1307, USA. |
---|
24 | */ |
---|
25 | |
---|
26 | #include "OneDimensional.h" |
---|
27 | |
---|
28 | namespace theplu { |
---|
29 | namespace yat { |
---|
30 | namespace regression { |
---|
31 | |
---|
32 | OneDimensional::OneDimensional(void) |
---|
33 | : chisq_(0) |
---|
34 | { |
---|
35 | } |
---|
36 | |
---|
37 | OneDimensional::~OneDimensional(void) |
---|
38 | { |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | double OneDimensional::chisq(void) const |
---|
43 | { |
---|
44 | return chisq_; |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | double OneDimensional::prediction_error2(const double x) const |
---|
49 | { |
---|
50 | return s2()+standard_error2(x); |
---|
51 | } |
---|
52 | |
---|
53 | |
---|
54 | std::ostream& OneDimensional::print(std::ostream& os, const double min, |
---|
55 | double max, const unsigned int n) const |
---|
56 | { |
---|
57 | double dx; |
---|
58 | if (n>1) |
---|
59 | dx=(max-min)/(n-1); |
---|
60 | else{ |
---|
61 | dx=1.0; |
---|
62 | max=min; |
---|
63 | } |
---|
64 | |
---|
65 | for ( double x=min; x<=max; x+=dx) { |
---|
66 | double y = predict(x); |
---|
67 | double y_err = sqrt(prediction_error2(x)); |
---|
68 | os << x << "\t" << y << "\t" << y_err << "\n"; |
---|
69 | } |
---|
70 | return os; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | double OneDimensional::r2(void) const |
---|
75 | { |
---|
76 | return 1 - chisq()/ap_.y_averager().sum_xx_centered(); |
---|
77 | } |
---|
78 | |
---|
79 | double OneDimensional::variance(void) const |
---|
80 | { |
---|
81 | return ap_.y_averager().variance(); |
---|
82 | } |
---|
83 | |
---|
84 | }}} // of namespaces regression, yat, and theplu |
---|