source: trunk/c++_tools/statistics/NaiveWeighted.h @ 586

Last change on this file since 586 was 586, checked in by Peter, 15 years ago

closes #23 redesign of regression classes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// $Id: NaiveWeighted.h 586 2006-06-19 09:56:04Z peter $
2
3#ifndef _theplu_statistics_regression_naive_weighted_
4#define _theplu_statistics_regression_naive_weighted_
5
6#include <c++_tools/statistics/OneDimensionalWeighted.h>
7
8#include <c++_tools/gslapi/vector.h>
9//#include <c++_tools/statistics/AveragerPairWeighted.h>
10
11#include <cmath>
12#include <iostream>
13#include <utility>
14
15
16namespace theplu {
17namespace statistics {
18namespace regression {
19
20  ///
21  /// @brief naive fitting.
22  ///
23  /// @todo document
24  ///
25  class NaiveWeighted : public OneDimensionalWeighted
26  {
27 
28  public:
29    ///
30    /// Default Constructor.
31    ///
32    inline NaiveWeighted(void) 
33      : OneDimensionalWeighted(), m_(0.0), m_err_(0.0) {}
34
35    ///
36    /// Destructor
37    ///
38    virtual ~NaiveWeighted(void) {};
39         
40    ///
41    /// This function computes the best-fit for the naive model \f$ y
42    /// = m \f$ from vectors \a x and \a y, by minimizing \f$ \sum
43    /// w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to
44    /// the inverse of the variance for \f$ y_i \f$
45    ///
46    void fit(const gslapi::vector& x,
47             const gslapi::vector& y,
48             const gslapi::vector& w);
49
50    ///
51    /// Function predicting value using the naive model, i.e. a
52    /// weighted average.
53    ///
54    inline double predict(const double x) const { return m_; }
55
56    ///
57    /// @return expected prediction error for a new data point in @a x
58    /// with weight @a w
59    ///
60    inline double prediction_error(const double x, const double w=1) const
61    { return sqrt(m_err_*m_err_ + s2_/w); }
62
63    ///
64    /// @return estimation of error of model value in @a x
65    ///
66    inline double standard_error(const double x) const
67    { return m_err_; }
68
69  private:
70    ///
71    /// Copy Constructor. (not implemented)
72    ///
73    NaiveWeighted(const NaiveWeighted&);
74
75    double m_;
76    double m_err_; // error of estimation of mean m_
77
78  };
79
80
81}}} // of namespaces regression, statisitcs and thep
82
83#endif
Note: See TracBrowser for help on using the repository browser.