1 | // $Id: NaiveWeighted.cc 729 2007-01-05 16:00:15Z peter $ |
---|

2 | |
---|

3 | /* |
---|

4 | Copyright (C) The authors contributing to this file. |
---|

5 | |
---|

6 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|

7 | |
---|

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

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

10 | published by the Free Software Foundation; either version 2 of the |
---|

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

12 | |
---|

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

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

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

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

17 | |
---|

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

19 | along with this program; if not, write to the Free Software |
---|

20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|

21 | 02111-1307, USA. |
---|

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::vector& x, |
---|

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

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

47 | { |
---|

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

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

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

51 | ap_.add_values(x,y,utility::vector(x.size(),1.0), w); |
---|

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

53 | } |
---|

54 | |
---|

55 | |
---|

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

57 | { |
---|

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

59 | } |
---|

60 | |
---|

61 | |
---|

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

63 | { |
---|

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

65 | } |
---|

66 | |
---|

67 | |
---|

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

69 | { |
---|

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

71 | } |
---|

72 | |
---|

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