yat/regression/Linear.h

Code
Comments
Other
Rev Date Author Line
681 11 Oct 06 jari 1 #ifndef _theplu_yat_regression_linear_
681 11 Oct 06 jari 2 #define _theplu_yat_regression_linear_
193 27 Oct 04 peter 3
616 31 Aug 06 jari 4 // $Id$
616 31 Aug 06 jari 5
675 10 Oct 06 jari 6 /*
4359 23 Aug 23 peter 7   Copyright (C) 2004, 2005, 2006 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 9   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 10   Copyright (C) 2010 Peter Johansson
193 27 Oct 04 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 "OneDimensional.h"
675 10 Oct 06 jari 29
221 30 Dec 04 peter 30 #include <cmath>
193 27 Oct 04 peter 31
193 27 Oct 04 peter 32 namespace theplu {
680 11 Oct 06 jari 33 namespace yat {
616 31 Aug 06 jari 34   namespace utility {
1019 01 Feb 08 peter 35     class VectorBase;
616 31 Aug 06 jari 36   }
383 12 Aug 05 jari 37 namespace regression {
383 12 Aug 05 jari 38
713 21 Dec 06 peter 39   /**
4078 26 Aug 21 peter 40      @brief linear regression.
4078 26 Aug 21 peter 41
713 21 Dec 06 peter 42      Data are modeled as \f$ y_i = \alpha + \beta (x_i-m_x) +
713 21 Dec 06 peter 43      \epsilon_i \f$.
713 21 Dec 06 peter 44   */
4078 26 Aug 21 peter 45   class Linear : public OneDimensional
193 27 Oct 04 peter 46   {
4078 26 Aug 21 peter 47
193 27 Oct 04 peter 48   public:
193 27 Oct 04 peter 49     ///
703 18 Dec 06 jari 50     /// @brief The default constructor
193 27 Oct 04 peter 51     ///
703 18 Dec 06 jari 52     Linear(void);
193 27 Oct 04 peter 53
193 27 Oct 04 peter 54     ///
4078 26 Aug 21 peter 55     /// @brief The destructor
193 27 Oct 04 peter 56     ///
703 18 Dec 06 jari 57     virtual ~Linear(void);
4078 26 Aug 21 peter 58
713 21 Dec 06 peter 59     /**
713 21 Dec 06 peter 60        The parameter \f$ \alpha \f$ is estimated as \f$
713 21 Dec 06 peter 61        \frac{1}{n}\sum y_i \f$
4078 26 Aug 21 peter 62
713 21 Dec 06 peter 63        @return the parameter \f$ \alpha \f$
713 21 Dec 06 peter 64     */
718 26 Dec 06 jari 65     double alpha(void) const;
216 29 Dec 04 peter 66
713 21 Dec 06 peter 67     /**
2202 21 Feb 10 peter 68        The variance is estimated as \f$ \frac{s^2}{n}
726 04 Jan 07 peter 69        \f$ where \f$ s^2 = \frac{\sum \epsilon^2}{n-2} \f$
4078 26 Aug 21 peter 70
2202 21 Feb 10 peter 71        @return variance of parameter \f$ \alpha \f$
713 21 Dec 06 peter 72     */
726 04 Jan 07 peter 73     double alpha_var(void) const;
193 27 Oct 04 peter 74
713 21 Dec 06 peter 75     /**
713 21 Dec 06 peter 76        The parameter \f$ \beta \f$ is estimated as \f$
713 21 Dec 06 peter 77        \frac{\textrm{Cov}(x,y)}{\textrm{Var}(x)} \f$
4078 26 Aug 21 peter 78
713 21 Dec 06 peter 79        @return the parameter \f$ \beta \f$
713 21 Dec 06 peter 80     */
718 26 Dec 06 jari 81     double beta(void) const;
207 02 Nov 04 peter 82
713 21 Dec 06 peter 83     /**
2202 21 Feb 10 peter 84        The variance is estimated as \f$ \frac{s^2}{\sum
726 04 Jan 07 peter 85        (x-m_x)^2} \f$ where \f$ s^2 = \frac{\sum \epsilon^2}{n-2} \f$
726 04 Jan 07 peter 86
2202 21 Feb 10 peter 87        @return variance of parameter \f$ \beta \f$
713 21 Dec 06 peter 88     */
726 04 Jan 07 peter 89     double beta_var(void) const;
718 26 Dec 06 jari 90
713 21 Dec 06 peter 91     /**
713 21 Dec 06 peter 92        Model is fitted by minimizing \f$ \sum{(y_i - \alpha - \beta
713 21 Dec 06 peter 93        (x-m_x))^2} \f$. By construction \f$ \alpha \f$ and \f$ \beta \f$
713 21 Dec 06 peter 94        are independent.
713 21 Dec 06 peter 95     */
1019 01 Feb 08 peter 96     void fit(const utility::VectorBase& x, const utility::VectorBase& y) ;
4078 26 Aug 21 peter 97
221 30 Dec 04 peter 98     ///
4078 26 Aug 21 peter 99     /// @return \f$ \alpha + \beta x \f$
702 26 Oct 06 peter 100     ///
586 19 Jun 06 peter 101     double predict(const double x) const;
213 04 Nov 04 peter 102
713 21 Dec 06 peter 103     /**
728 04 Jan 07 peter 104        \f$ \frac{\sum \epsilon_i^2}{N-2} \f$
728 04 Jan 07 peter 105
728 04 Jan 07 peter 106        @return variance of residuals
728 04 Jan 07 peter 107     */
728 04 Jan 07 peter 108     double s2(void) const;
728 04 Jan 07 peter 109
728 04 Jan 07 peter 110     /**
727 04 Jan 07 peter 111        The error of the model is estimated as \f$
727 04 Jan 07 peter 112        \textrm{alpha\_err}^2+\textrm{beta\_err}^2*(x-m_x)*(x-m_x)\f$
4078 26 Aug 21 peter 113
713 21 Dec 06 peter 114        @return estimated error of model in @a x
713 21 Dec 06 peter 115     */
727 04 Jan 07 peter 116     double standard_error2(const double x) const;
235 21 Feb 05 peter 117
221 30 Dec 04 peter 118
193 27 Oct 04 peter 119   private:
385 13 Aug 05 jari 120     ///
385 13 Aug 05 jari 121     /// Copy Constructor. (not implemented)
385 13 Aug 05 jari 122     ///
385 13 Aug 05 jari 123     Linear(const Linear&);
385 13 Aug 05 jari 124
221 30 Dec 04 peter 125     double alpha_;
221 30 Dec 04 peter 126     double alpha_var_;
221 30 Dec 04 peter 127     double beta_;
221 30 Dec 04 peter 128     double beta_var_;
193 27 Oct 04 peter 129    };
193 27 Oct 04 peter 130
681 11 Oct 06 jari 131 }}} // of namespaces regression, yat, and theplu
193 27 Oct 04 peter 132
193 27 Oct 04 peter 133 #endif