1 | // $Id: Naive.h 429 2005-12-08 19:50:11Z 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 | |
---|

10 | #include <iostream> |
---|

11 | #include <utility> |
---|

12 | |
---|

13 | |
---|

14 | namespace theplu { |
---|

15 | namespace statistics { |
---|

16 | namespace regression { |
---|

17 | |
---|

18 | /// |
---|

19 | /// @bief naive fitting. |
---|

20 | /// |
---|

21 | /// @todo document |
---|

22 | /// |
---|

23 | class Naive : public OneDimensional |
---|

24 | { |
---|

25 | |
---|

26 | public: |
---|

27 | /// |
---|

28 | /// Default Constructor. |
---|

29 | /// |
---|

30 | inline Naive(void) : OneDimensional(), m_(0.0), m_err_(0.0) {} |
---|

31 | |
---|

32 | /// |
---|

33 | /// Copy Constructor. (not implemented) |
---|

34 | /// |
---|

35 | Naive(const Naive&); |
---|

36 | |
---|

37 | /// |
---|

38 | /// Destructor |
---|

39 | /// |
---|

40 | virtual ~Naive(void) {}; |
---|

41 | |
---|

42 | /// |
---|

43 | /// This function computes the best-fit for the naive model \f$ y |
---|

44 | /// = m \f$ from vectors \a x and \a y, by minimizing \f$ |
---|

45 | /// \sum{(y_i-m)^2} \f$. This function is the same as using the |
---|

46 | /// weighted version with unity weights. |
---|

47 | /// |
---|

48 | void fit(const gslapi::vector& x, const gslapi::vector& y); |
---|

49 | |
---|

50 | /// |
---|

51 | /// Function predicting value using the naive model. \a y_err is |
---|

52 | /// the expected deviation from the line for a new data point. The |
---|

53 | /// error has two components: the variance of point and error in |
---|

54 | /// estimation of the mean. |
---|

55 | /// |
---|

56 | void predict(const double x, double& y, double& y_err) ; |
---|

57 | |
---|

58 | /// |
---|

59 | /// @return header for print() |
---|

60 | /// |
---|

61 | std::ostream& print_header(std::ostream&) const; |
---|

62 | |
---|

63 | |
---|

64 | private: |
---|

65 | double s2_; // noise level - the typical variance for a point with |
---|

66 | // weight w is s2/w |
---|

67 | double m_; |
---|

68 | double m_err_; // error of estimation of mean m_ |
---|

69 | |
---|

70 | }; |
---|

71 | |
---|

72 | |
---|

73 | }}} // of namespaces regression, statisitcs and thep |
---|

74 | |
---|

75 | #endif |
---|