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

Last change on this file since 831 was 831, checked in by Peter, 16 years ago

Refs #185.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: NaiveWeighted.cc 831 2007-03-27 13:22:09Z peter $
2
3/*
4  Copyright (C) 2005 Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2007 Peter Johansson
7
8  This file is part of the yat library, http://lev.thep.lu.se/trac/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 "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::vector& x,
47                          const utility::vector& y,
48                          const utility::vector& w)
49  {
50    assert(x.size()==y.size());
51    assert(y.size()==w.size());
52    ap_.reset();
53    ap_.add_values(x,y,utility::vector(x.size(),1.0), w);
54    chisq_ = ap_.y_averager().sum_xx_centered();
55  }
56
57
58  double NaiveWeighted::predict(const double x) const
59  {
60    return ap_.y_averager().mean();
61  }
62
63
64  double NaiveWeighted::s2(double w) const
65  {
66    return chisq_/(w*(ap_.y_averager().n()-1));
67  }
68
69
70  double NaiveWeighted::standard_error2(const double x) const
71  { 
72    return chisq_/( (ap_.y_averager().n()-1)*ap_.y_averager().sum_w() );
73  }
74
75}}} // of namespaces regression, yat, and theplu
Note: See TracBrowser for help on using the repository browser.