source: trunk/lib/statistics/Naive.h @ 389

Last change on this file since 389 was 389, checked in by Peter, 18 years ago

moved kernel to regression namespace and tried to fix some dox issues

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1// $Id: Naive.h 389 2005-08-15 11:37:07Z peter $
2
3#ifndef _theplu_statistics_regression_naive_
4#define _theplu_statistics_regression_naive_
5
6#include <c++_tools/statistics/OneDimensional.h>
7
8#include <c++_tools/gslapi/vector.h>
9#include <c++_tools/statistics/Averager.h>
10#include <c++_tools/statistics/AveragerWeighted.h>
11
12#include <iostream>
13#include <utility>
14
15
16namespace theplu {
17namespace statistics {
18namespace regression {
19
20  ///
21  /// @bief naive fitting.
22  ///
23  /// @todo document
24  ///
25  class Naive : public OneDimensional
26  {
27 
28  public:
29    ///
30    /// Default Constructor.
31    ///
32    inline Naive(void) : OneDimensional(), m_(0.0), m_err_(0.0) {}
33
34    ///
35    /// Copy Constructor. (not implemented)
36    ///
37    Naive(const Naive&);
38
39    ///
40    /// Destructor
41    ///
42    virtual ~Naive(void) {};
43         
44    ///
45    /// This function computes the best-fit for the naive model \f$ y
46    /// = m \f$ from vectors \a x and \a y, by minimizing \f$
47    /// \sum{(y_i-m)^2} \f$. This function is the same as using the
48    /// weighted version with unity weights.
49    ///
50    void fit(const gslapi::vector& x, const gslapi::vector& y);
51
52    ///
53    /// This function computes the best-fit for the naive model \f$ y
54    /// = m \f$ from vectors \a x and \a y, by minimizing \f$ \sum
55    /// w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to
56    /// the inverse of the variance for \f$ y_i \f$
57    ///
58    void fit(const gslapi::vector& x,
59             const gslapi::vector& y,
60             const gslapi::vector& w);
61
62    ///
63    /// Function predicting value using the naive model. \a y_err is
64    /// the expected deviation from the line for a new data point. The
65    /// weight for the new point can be specified. A smaller weight
66    /// means larger error. The error has two components: the variance
67    /// of point and error in estimation of m_.
68    ///
69    void predict(const double x, double& y, double& y_err, 
70                 const double w=1) ;
71
72    ///
73    /// @return prediction value and parameters
74    ///
75    std::ostream& print(std::ostream&) const;
76             
77    ///
78    /// @return header for print()
79    ///
80    std::ostream& print_header(std::ostream&) const;
81             
82         
83  private:
84    double s2_; // noise level - the typical variance for a point with
85                // weight w is s2/w
86    double m_;
87    double m_err_; // error of estimation of mean m_
88
89  };
90
91
92}}} // of namespaces regression, statisitcs and thep
93
94#endif
Note: See TracBrowser for help on using the repository browser.