1 | // $Id: RegressionNaive.h 235 2005-02-21 14:53:48Z peter $ |
---|
2 | |
---|
3 | #ifndef _theplu_statistics_regression_naive_ |
---|
4 | #define _theplu_statistics_regression_naive_ |
---|
5 | |
---|
6 | // C++ tools include |
---|
7 | ///////////////////// |
---|
8 | #include "Averager.h" |
---|
9 | #include "Regression.h" |
---|
10 | #include "vector.h" |
---|
11 | #include "WeightedAverager.h" |
---|
12 | // Standard C++ includes |
---|
13 | //////////////////////// |
---|
14 | //#include <gsl/gsl_fit.h> |
---|
15 | #include <iostream> |
---|
16 | #include <utility> |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | namespace theplu { |
---|
21 | namespace statistics { |
---|
22 | |
---|
23 | /// |
---|
24 | /// Class for Regression. |
---|
25 | /// |
---|
26 | |
---|
27 | class RegressionNaive : public Regression |
---|
28 | { |
---|
29 | |
---|
30 | public: |
---|
31 | /// |
---|
32 | /// Default Constructor. |
---|
33 | /// |
---|
34 | RegressionNaive(void); |
---|
35 | |
---|
36 | /// |
---|
37 | /// Copy Constructor. (not implemented) |
---|
38 | /// |
---|
39 | RegressionNaive(const RegressionNaive&); |
---|
40 | |
---|
41 | /// |
---|
42 | /// Destructor |
---|
43 | /// |
---|
44 | virtual ~RegressionNaive(void) {}; |
---|
45 | |
---|
46 | /// |
---|
47 | /// This function computes the best-fit for the naive model \f$ y |
---|
48 | /// = m \f$ from vectors \a x and \a y, by minimizing \f$ |
---|
49 | /// \sum{(y_i-m)^2} \f$. This function is the same as using the |
---|
50 | /// weighted version with unity weights. |
---|
51 | /// |
---|
52 | void fit(const gslapi::vector& x, const gslapi::vector& y); |
---|
53 | |
---|
54 | /// |
---|
55 | /// This function computes the best-fit for the naive model \f$ y |
---|
56 | /// = m \f$ from vectors \a x and \a y, by minimizing \f$ \sum |
---|
57 | /// w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to |
---|
58 | /// the inverse of the variance for \f$ y_i \f$ |
---|
59 | /// |
---|
60 | void fit(const gslapi::vector& x, |
---|
61 | const gslapi::vector& y, |
---|
62 | const gslapi::vector& w); |
---|
63 | |
---|
64 | /// |
---|
65 | /// Function predicting value using the naive model. \a y_err is |
---|
66 | /// the expected deviation from the line for a new data point. The |
---|
67 | /// weight for the new point can be specified. A smaller weight |
---|
68 | /// means larger error. The error has two components: the variance |
---|
69 | /// of point and error in estimation of m_. |
---|
70 | /// |
---|
71 | void predict(const double x, double& y, double& y_err, |
---|
72 | const double w) ; |
---|
73 | |
---|
74 | /// |
---|
75 | /// @return prediction value and parameters |
---|
76 | /// |
---|
77 | std::ostream& print(std::ostream&) const; |
---|
78 | |
---|
79 | /// |
---|
80 | /// @return header for print() |
---|
81 | /// |
---|
82 | std::ostream& print_header(std::ostream&) const; |
---|
83 | |
---|
84 | |
---|
85 | private: |
---|
86 | double s2_; // noise level - the typical variance for a point with |
---|
87 | // weight w is s2/w |
---|
88 | double m_; |
---|
89 | double m_err_; // error of estimation of mean m_ |
---|
90 | |
---|
91 | }; |
---|
92 | |
---|
93 | }} // of namespace statistics and namespace theplu |
---|
94 | |
---|
95 | #endif |
---|
96 | |
---|