source: trunk/yat/regression/OneDimensional.cc @ 2532

Last change on this file since 2532 was 2532, checked in by Peter, 10 years ago

prefer <iosfwd> and <ostream>

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