yat/regression/NaiveWeighted.h

Code
Comments
Other
Rev Date Author Line
681 11 Oct 06 jari 1 #ifndef _theplu_yat_regression_naiveweighted_
681 11 Oct 06 jari 2 #define _theplu_yat_regression_naiveweighted_
429 08 Dec 05 peter 3
616 31 Aug 06 jari 4 // $Id$
616 31 Aug 06 jari 5
675 10 Oct 06 jari 6 /*
831 27 Mar 07 peter 7   Copyright (C) 2005 Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 9   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 10   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
429 08 Dec 05 peter 11
1437 25 Aug 08 peter 12   This file is part of the yat library, http://dev.thep.lu.se/yat
675 10 Oct 06 jari 13
675 10 Oct 06 jari 14   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 15   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 16   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 17   License, or (at your option) any later version.
675 10 Oct 06 jari 18
675 10 Oct 06 jari 19   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 20   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 22   General Public License for more details.
675 10 Oct 06 jari 23
675 10 Oct 06 jari 24   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 25   along with yat. If not, see <http://www.gnu.org/licenses/>.
675 10 Oct 06 jari 26 */
675 10 Oct 06 jari 27
680 11 Oct 06 jari 28 #include "OneDimensionalWeighted.h"
675 10 Oct 06 jari 29
586 19 Jun 06 peter 30 #include <cmath>
429 08 Dec 05 peter 31 #include <utility>
429 08 Dec 05 peter 32
429 08 Dec 05 peter 33 namespace theplu {
680 11 Oct 06 jari 34 namespace yat {
616 31 Aug 06 jari 35   namespace utility {
1020 01 Feb 08 peter 36     class VectorBase;
616 31 Aug 06 jari 37   }
429 08 Dec 05 peter 38 namespace regression {
429 08 Dec 05 peter 39
429 08 Dec 05 peter 40   ///
429 08 Dec 05 peter 41   /// @brief naive fitting.
429 08 Dec 05 peter 42   ///
2842 17 Sep 12 peter 43   class NaiveWeighted : public OneDimensionalWeighted
429 08 Dec 05 peter 44   {
2842 17 Sep 12 peter 45
429 08 Dec 05 peter 46   public:
429 08 Dec 05 peter 47     ///
703 18 Dec 06 jari 48     /// @brief The default constructor
429 08 Dec 05 peter 49     ///
703 18 Dec 06 jari 50     NaiveWeighted(void);
429 08 Dec 05 peter 51
429 08 Dec 05 peter 52     ///
703 18 Dec 06 jari 53     /// @brief The destructor
429 08 Dec 05 peter 54     ///
703 18 Dec 06 jari 55     virtual ~NaiveWeighted(void);
2842 17 Sep 12 peter 56
702 26 Oct 06 peter 57     /**
702 26 Oct 06 peter 58        This function computes the best-fit for the naive model \f$ y
702 26 Oct 06 peter 59        = m \f$ from vectors \a x and \a y, by minimizing \f$ \sum
702 26 Oct 06 peter 60        w_i(y_i-m)^2 \f$. The weight \f$ w_i \f$ is proportional to
702 26 Oct 06 peter 61        the inverse of the variance for \f$ y_i \f$
702 26 Oct 06 peter 62     */
1020 01 Feb 08 peter 63     void fit(const utility::VectorBase& x,
1020 01 Feb 08 peter 64              const utility::VectorBase& y,
1020 01 Feb 08 peter 65              const utility::VectorBase& w);
429 08 Dec 05 peter 66
429 08 Dec 05 peter 67     ///
495 11 Jan 06 peter 68     /// Function predicting value using the naive model, i.e. a
2842 17 Sep 12 peter 69     /// weighted average.
429 08 Dec 05 peter 70     ///
718 26 Dec 06 jari 71     double predict(const double x) const;
429 08 Dec 05 peter 72
729 05 Jan 07 peter 73     /**
729 05 Jan 07 peter 74        \f$ \frac{\sum w_i\epsilon_i^2}{ w \left(\frac{\left(\sum
729 05 Jan 07 peter 75        w_i\right)^2}{\sum w_i^2}-1\right)} \f$
586 19 Jun 06 peter 76
729 05 Jan 07 peter 77        Rescaling all weights, both in fit and the passed @a w, results
729 05 Jan 07 peter 78        in the same returned value.
586 19 Jun 06 peter 79
729 05 Jan 07 peter 80        @return Conditional variance of Y with weight @a w.
729 05 Jan 07 peter 81     */
729 05 Jan 07 peter 82     double s2(const double w=1) const;
729 05 Jan 07 peter 83
729 05 Jan 07 peter 84     /**
729 05 Jan 07 peter 85        \f$ \frac{\sum w_i\epsilon_i^2}{ \left(\frac{\left(\sum
729 05 Jan 07 peter 86        w_i\right)^2}{\sum w_i^2}-1\right)\sum w_i} \f$
729 05 Jan 07 peter 87
729 05 Jan 07 peter 88        @return estimated squared error of model value in @a x
729 05 Jan 07 peter 89     */
729 05 Jan 07 peter 90     double standard_error2(const double x) const;
729 05 Jan 07 peter 91
429 08 Dec 05 peter 92   private:
429 08 Dec 05 peter 93     ///
429 08 Dec 05 peter 94     /// Copy Constructor. (not implemented)
429 08 Dec 05 peter 95     ///
429 08 Dec 05 peter 96     NaiveWeighted(const NaiveWeighted&);
429 08 Dec 05 peter 97
429 08 Dec 05 peter 98    };
429 08 Dec 05 peter 99
681 11 Oct 06 jari 100 }}} // of namespaces regression, yat, and theplu
429 08 Dec 05 peter 101
429 08 Dec 05 peter 102 #endif