source: trunk/yat/regression/OneDimensionalWeighted.h @ 1703

Last change on this file since 1703 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1#ifndef _theplu_yat_regression_onedimensioanlweighted_
2#define _theplu_yat_regression_onedimensioanlweighted_
3
4// $Id: OneDimensionalWeighted.h 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2005 Peter Johansson
8  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2008 Peter Johansson
10
11  This file is part of the yat library, http://dev.thep.lu.se/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 3 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with yat. If not, see <http://www.gnu.org/licenses/>.
25*/
26
27#include "yat/statistics/AveragerPairWeighted.h"
28
29#include <ostream>
30
31namespace theplu {
32namespace yat {
33namespace utility {
34  class VectorBase;
35}
36namespace regression {
37 
38  ///
39  /// @brief Interface Class for One Dimensional fitting in a weighted
40  /// fashion.
41  ///
42  class OneDimensionalWeighted
43  {
44 
45  public:
46    ///
47    /// Default Constructor.
48    ///
49    OneDimensionalWeighted(void);
50
51    ///
52    /// Destructor
53    ///
54    virtual ~OneDimensionalWeighted(void);
55         
56    /**
57       This function computes the best-fit given a model (see
58       specific class for details) by minimizing \f$
59       \sum{w_i(\hat{y_i}-y_i)^2} \f$, where \f$ \hat{y} \f$ is the
60       fitted value. The weight \f$ w_i \f$ should be proportional
61       to the inverse of the variance for \f$ y_i \f$
62    */
63    virtual void fit(const utility::VectorBase& x, const utility::VectorBase& y, 
64                     const utility::VectorBase& w)=0;
65
66    ///
67    /// @return expected value in @a x according to the fitted model
68    ///
69    virtual double predict(const double x) const=0;
70
71    /**
72       The prediction error is defined as expected squared deviation a
73       new data point (with weight @a w) will be from the model
74       value \f$ E((Y|x - \hat{y}(x))^2|w) \f$ and is typically
75       divided into the conditional variance ( see s2() )
76       given \f$ x \f$ and the squared standard error ( see
77       standard_error2() ) of the model estimation in \f$ x \f$.
78
79       \f$ E((Y|x - E(Y|x))^2|w) + E((E(Y|x) - \hat{y}(x))^2) \f$
80
81       @return expected prediction error for a new data point in @a x
82       with weight @a w.
83    */
84    double prediction_error2(const double x, const double w=1.0) const; 
85
86    /**
87       r2 is defined as \f$ \frac{\sum
88       w_i(y_i-\hat{y}_i)^2}{\sum w_i(y_i-m_y)^2} \f$ or the fraction
89       of the variance explained by the regression model.
90    */
91    double r2(void) const; 
92
93    /**
94       \f$ s^2 \f$ is the estimation of variance of residuals or
95       equivalently the conditional variance of Y.
96
97       @return Conditional variance of Y
98    */
99    virtual double s2(double w=1) const=0;
100
101    /**
102       The standard error is defined as \f$ E((Y|x,w -
103       \hat{y}(x))^2) \f$
104
105       @return error of model value in @a x
106    */
107    virtual double standard_error2(const double x) const=0;
108
109  protected:
110    ///
111    /// Averager for pair of x and y
112    ///
113    statistics::AveragerPairWeighted ap_;
114
115    /**
116       @brief Chi-squared
117       
118       Chi-squared is defined as the \f$
119       \sum{w_i(\hat{y_i}-y_i)^2} \f$
120    */
121    double chisq_;
122
123  private:
124  };
125
126}}} // of namespaces regression, yat, and theplu
127
128#endif
Note: See TracBrowser for help on using the repository browser.