1 | // $Id: NaiveWeighted.cc 1487 2008-09-10 08:41:36Z jari $ |
---|

2 | |
---|

3 | /* |
---|

4 | Copyright (C) 2005 Peter Johansson |
---|

5 | Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson |
---|

6 | Copyright (C) 2008 Peter Johansson |
---|

7 | |
---|

8 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|

9 | |
---|

10 | The yat library is free software; you can redistribute it and/or |
---|

11 | modify it under the terms of the GNU General Public License as |
---|

12 | published by the Free Software Foundation; either version 3 of the |
---|

13 | License, or (at your option) any later version. |
---|

14 | |
---|

15 | The yat library is distributed in the hope that it will be useful, |
---|

16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|

17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|

18 | General Public License for more details. |
---|

19 | |
---|

20 | You should have received a copy of the GNU General Public License |
---|

21 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|

22 | */ |
---|

23 | |
---|

24 | #include "NaiveWeighted.h" |
---|

25 | #include "OneDimensional.h" |
---|

26 | #include "yat/statistics/AveragerWeighted.h" |
---|

27 | #include "yat/utility/Vector.h" |
---|

28 | |
---|

29 | #include <cassert> |
---|

30 | |
---|

31 | namespace theplu { |
---|

32 | namespace yat { |
---|

33 | namespace regression { |
---|

34 | |
---|

35 | NaiveWeighted::NaiveWeighted(void) |
---|

36 | : OneDimensionalWeighted() |
---|

37 | { |
---|

38 | } |
---|

39 | |
---|

40 | NaiveWeighted::~NaiveWeighted(void) |
---|

41 | { |
---|

42 | } |
---|

43 | |
---|

44 | void NaiveWeighted::fit(const utility::VectorBase& x, |
---|

45 | const utility::VectorBase& y, |
---|

46 | const utility::VectorBase& w) |
---|

47 | { |
---|

48 | assert(x.size()==y.size()); |
---|

49 | assert(y.size()==w.size()); |
---|

50 | ap_.reset(); |
---|

51 | utility::Vector dummy(x.size(),1.0); |
---|

52 | add(ap_, x.begin(), x.end(), y.begin(),dummy.begin(), w.begin()); |
---|

53 | chisq_ = ap_.y_averager().sum_xx_centered(); |
---|

54 | } |
---|

55 | |
---|

56 | |
---|

57 | double NaiveWeighted::predict(const double x) const |
---|

58 | { |
---|

59 | return ap_.y_averager().mean(); |
---|

60 | } |
---|

61 | |
---|

62 | |
---|

63 | double NaiveWeighted::s2(double w) const |
---|

64 | { |
---|

65 | return chisq_/(w*(ap_.y_averager().n()-1)); |
---|

66 | } |
---|

67 | |
---|

68 | |
---|

69 | double NaiveWeighted::standard_error2(const double x) const |
---|

70 | { |
---|

71 | return chisq_/( (ap_.y_averager().n()-1)*ap_.y_averager().sum_w() ); |
---|

72 | } |
---|

73 | |
---|

74 | }}} // of namespaces regression, yat, and theplu |
---|