source: trunk/yat/regression/Naive.cc @ 1437

Last change on this file since 1437 was 1437, checked in by Peter, 13 years ago

merge patch release 0.4.2 to trunk. Delta 0.4.2-0.4.1

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.7 KB
Line 
1// $Id: Naive.cc 1437 2008-08-25 17:55:00Z peter $
2
3/*
4  Copyright (C) 2004 Peter Johansson
5  Copyright (C) 2005, 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 "Naive.h"
27#include "OneDimensional.h"
28#include "yat/statistics/Averager.h"
29#include "yat/statistics/AveragerWeighted.h"
30#include "yat/utility/VectorBase.h"
31
32#include <cmath>
33#include <iostream>
34
35namespace theplu {
36namespace yat {
37namespace regression {
38
39  Naive::Naive(void)
40    : OneDimensional(), mse_(0.0)
41  {
42  }
43
44  Naive::~Naive(void)
45  {
46  }
47
48
49  void Naive::fit(const utility::VectorBase& x, const utility::VectorBase& y)
50  {
51    ap_.reset();
52    for (size_t i=0; i<y.size(); i++)
53      ap_.add(x(i),y(i));
54    chisq_ = ap_.y_averager().sum_xx_centered();
55  }
56
57
58  double Naive::predict(const double x) const
59  { 
60    return ap_.y_averager().mean(); 
61  }
62 
63
64  double Naive::s2(void) const
65  {
66    return chisq()/(ap_.n()-1);
67  }
68
69
70  double Naive::standard_error2(const double x) const
71  {
72    return s2()/ap_.n();
73  }
74
75}}} // of namespaces regression, yat, and theplu
Note: See TracBrowser for help on using the repository browser.