source: trunk/lib/statistics/NaiveWeighted.h @ 495

Last change on this file since 495 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.9 KB
Line 
1// $Id: NaiveWeighted.h 495 2006-01-11 17:27:22Z 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 <iostream>
12#include <utility>
13
14
15namespace theplu {
16namespace statistics {
17namespace regression {
18
19  ///
20  /// @brief naive fitting.
21  ///
22  /// @todo document
23  ///
24  class NaiveWeighted : public OneDimensionalWeighted
25  {
26 
27  public:
28    ///
29    /// Default Constructor.
30    ///
31    inline NaiveWeighted(void) 
32      : OneDimensionalWeighted(), m_(0.0), m_err_(0.0) {}
33
34    ///
35    /// Destructor
36    ///
37    virtual ~NaiveWeighted(void) {};
38         
39    ///
40    /// This function computes the best-fit for the naive model \f$ y
41    /// = m \f$ from vectors \a x and \a y, by minimizing \f$ \sum
42    /// w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to
43    /// the inverse of the variance for \f$ y_i \f$
44    ///
45    void fit(const gslapi::vector& x,
46             const gslapi::vector& y,
47             const gslapi::vector& w);
48
49    ///
50    /// Function predicting value using the naive model, i.e. a
51    /// weighted average. \a y_err is the standard error of the
52    /// weighted mean
53    ///
54    /// @see AveragerWeighted::standard_error
55    ///
56    void predict(const double x, double& y, double& y_err, 
57                 const double w=1) ;
58
59    ///
60    /// @return prediction value and parameters
61    ///
62    std::ostream& print(std::ostream&) const;
63             
64    ///
65    /// @return header for print()
66    ///
67    std::ostream& print_header(std::ostream&) const;
68             
69         
70  private:
71    ///
72    /// Copy Constructor. (not implemented)
73    ///
74    NaiveWeighted(const NaiveWeighted&);
75
76    double s2_; // noise level - the typical variance for a point with
77                // weight w is s2/w
78    double m_;
79    double m_err_; // error of estimation of mean m_
80
81  };
82
83
84}}} // of namespaces regression, statisitcs and thep
85
86#endif
Note: See TracBrowser for help on using the repository browser.