source: trunk/c++_tools/statistics/NaiveWeighted.cc @ 575

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

modified interface for Regression::Local

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1// $Id: NaiveWeighted.cc 495 2006-01-11 17:27:22Z peter $
2
3#include <c++_tools/statistics/NaiveWeighted.h>
4
5#include <c++_tools/statistics/AveragerWeighted.h>
6#include <c++_tools/statistics/OneDimensional.h>
7#include <c++_tools/gslapi/vector.h>
8
9#include <iostream>
10
11
12namespace theplu {
13namespace statistics {
14namespace regression {
15
16
17  void NaiveWeighted::fit(const gslapi::vector& x,
18                  const gslapi::vector& y,
19                  const gslapi::vector& w)
20  {
21    AveragerWeighted a;
22    for (size_t i=0; i<y.size(); i++)
23      a.add(y(i), w(i));
24    m_=a.mean();
25    m_err_=a.standard_error();
26    s2_=m_err_*m_err_*w.sum(); 
27  }
28
29  void NaiveWeighted::predict(const double x, double& y, double& y_err, 
30                              const double w)
31  { 
32    x_ = x;
33    y = m_; 
34    y_err = m_err_;
35  }
36 
37  std::ostream& NaiveWeighted::print(std::ostream& s) const
38  {
39    s << x_ << "\t" 
40      << m_ << "\t"
41      << sqrt(m_err_*m_err_ + s2_);
42    return s;
43  }
44 
45  std::ostream& NaiveWeighted::print_header(std::ostream& s) const
46  {
47    s << "# column 1: x\n"
48      << "# column 2: y\n"
49      << "# column 3: y_err";
50    return s;
51  }
52
53
54}}} // of namespaces regression, statisitcs and thep
Note: See TracBrowser for help on using the repository browser.