yat/regression/Naive.cc

Code
Comments
Other
Rev Date Author Line
202 01 Nov 04 peter 1 // $Id$
202 01 Nov 04 peter 2
675 10 Oct 06 jari 3 /*
831 27 Mar 07 peter 4   Copyright (C) 2004 Peter Johansson
4359 23 Aug 23 peter 5   Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 6   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 7   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2012 Peter Johansson
235 21 Feb 05 peter 9
1437 25 Aug 08 peter 10   This file is part of the yat library, http://dev.thep.lu.se/yat
202 01 Nov 04 peter 11
675 10 Oct 06 jari 12   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 13   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 14   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 15   License, or (at your option) any later version.
675 10 Oct 06 jari 16
675 10 Oct 06 jari 17   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 18   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 20   General Public License for more details.
675 10 Oct 06 jari 21
675 10 Oct 06 jari 22   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 23   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 24 */
675 10 Oct 06 jari 25
2881 18 Nov 12 peter 26 #include <config.h>
2881 18 Nov 12 peter 27
680 11 Oct 06 jari 28 #include "Naive.h"
680 11 Oct 06 jari 29 #include "OneDimensional.h"
682 11 Oct 06 jari 30 #include "yat/statistics/Averager.h"
682 11 Oct 06 jari 31 #include "yat/statistics/AveragerWeighted.h"
1019 01 Feb 08 peter 32 #include "yat/utility/VectorBase.h"
675 10 Oct 06 jari 33
202 01 Nov 04 peter 34 namespace theplu {
680 11 Oct 06 jari 35 namespace yat {
383 12 Aug 05 jari 36 namespace regression {
202 01 Nov 04 peter 37
703 18 Dec 06 jari 38   Naive::Naive(void)
703 18 Dec 06 jari 39     : OneDimensional(), mse_(0.0)
703 18 Dec 06 jari 40   {
703 18 Dec 06 jari 41   }
703 18 Dec 06 jari 42
703 18 Dec 06 jari 43   Naive::~Naive(void)
703 18 Dec 06 jari 44   {
703 18 Dec 06 jari 45   }
703 18 Dec 06 jari 46
713 21 Dec 06 peter 47
1019 01 Feb 08 peter 48   void Naive::fit(const utility::VectorBase& x, const utility::VectorBase& y)
235 21 Feb 05 peter 49   {
429 08 Dec 05 peter 50     ap_.reset();
235 21 Feb 05 peter 51     for (size_t i=0; i<y.size(); i++)
429 08 Dec 05 peter 52       ap_.add(x(i),y(i));
729 05 Jan 07 peter 53     chisq_ = ap_.y_averager().sum_xx_centered();
235 21 Feb 05 peter 54   }
202 01 Nov 04 peter 55
713 21 Dec 06 peter 56
586 19 Jun 06 peter 57   double Naive::predict(const double x) const
4200 19 Aug 22 peter 58   {
4200 19 Aug 22 peter 59     return ap_.y_averager().mean();
235 21 Feb 05 peter 60   }
383 12 Aug 05 jari 61
4200 19 Aug 22 peter 62
728 04 Jan 07 peter 63   double Naive::s2(void) const
728 04 Jan 07 peter 64   {
728 04 Jan 07 peter 65     return chisq()/(ap_.n()-1);
728 04 Jan 07 peter 66   }
728 04 Jan 07 peter 67
728 04 Jan 07 peter 68
727 04 Jan 07 peter 69   double Naive::standard_error2(const double x) const
586 19 Jun 06 peter 70   {
728 04 Jan 07 peter 71     return s2()/ap_.n();
586 19 Jun 06 peter 72   }
383 12 Aug 05 jari 73
681 11 Oct 06 jari 74 }}} // of namespaces regression, yat, and theplu