source: trunk/yat/regression/NaiveWeighted.cc @ 1486

Last change on this file since 1486 was 1486, checked in by Jari Häkkinen, 13 years ago

Addresses #436.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: NaiveWeighted.cc 1486 2008-09-09 21:17:19Z jari $
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 3 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 "NaiveWeighted.h"
27#include "OneDimensional.h"
28#include "yat/statistics/AveragerWeighted.h"
29#include "yat/utility/Vector.h"
30
31#include <cassert>
32
33namespace theplu {
34namespace yat {
35namespace regression {
36
37  NaiveWeighted::NaiveWeighted(void)
38    : OneDimensionalWeighted()
39  {
40  }
41
42  NaiveWeighted::~NaiveWeighted(void)
43  {
44  }
45
46  void NaiveWeighted::fit(const utility::VectorBase& x,
47                          const utility::VectorBase& y,
48                          const utility::VectorBase& w)
49  {
50    assert(x.size()==y.size());
51    assert(y.size()==w.size());
52    ap_.reset();
53    utility::Vector dummy(x.size(),1.0);
54    add(ap_, x.begin(), x.end(), y.begin(),dummy.begin(), w.begin());
55    chisq_ = ap_.y_averager().sum_xx_centered();
56  }
57
58
59  double NaiveWeighted::predict(const double x) const
60  {
61    return ap_.y_averager().mean();
62  }
63
64
65  double NaiveWeighted::s2(double w) const
66  {
67    return chisq_/(w*(ap_.y_averager().n()-1));
68  }
69
70
71  double NaiveWeighted::standard_error2(const double x) const
72  { 
73    return chisq_/( (ap_.y_averager().n()-1)*ap_.y_averager().sum_w() );
74  }
75
76}}} // of namespaces regression, yat, and theplu
Note: See TracBrowser for help on using the repository browser.