#ifndef _theplu_yat_regression_onedimensioanlweighted_ #define _theplu_yat_regression_onedimensioanlweighted_ // $Id: OneDimensionalWeighted.h 1487 2008-09-10 08:41:36Z jari$ /* Copyright (C) 2005 Peter Johansson Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include "yat/statistics/AveragerPairWeighted.h" #include namespace theplu { namespace yat { namespace utility { class VectorBase; } namespace regression { /// /// @brief Interface Class for One Dimensional fitting in a weighted /// fashion. /// class OneDimensionalWeighted { public: /// /// Default Constructor. /// OneDimensionalWeighted(void); /// /// Destructor /// virtual ~OneDimensionalWeighted(void); /** This function computes the best-fit given a model (see specific class for details) by minimizing \f$\sum{w_i(\hat{y_i}-y_i)^2} \f$, where \f$\hat{y} \f$ is the fitted value. The weight \f$w_i \f$ should be proportional to the inverse of the variance for \f$y_i \f$ */ virtual void fit(const utility::VectorBase& x, const utility::VectorBase& y, const utility::VectorBase& w)=0; /// /// @return expected value in @a x according to the fitted model /// virtual double predict(const double x) const=0; /** The prediction error is defined as expected squared deviation a new data point (with weight @a w) will be from the model value \f$E((Y|x - \hat{y}(x))^2|w) \f$ and is typically divided into the conditional variance ( see s2() ) given \f$x \f$ and the squared standard error ( see standard_error2() ) of the model estimation in \f$x \f$. \f$E((Y|x - E(Y|x))^2|w) + E((E(Y|x) - \hat{y}(x))^2) \f$ @return expected prediction error for a new data point in @a x with weight @a w. */ double prediction_error2(const double x, const double w=1.0) const; /** r2 is defined as \f$\frac{\sum w_i(y_i-\hat{y}_i)^2}{\sum w_i(y_i-m_y)^2} \f$ or the fraction of the variance explained by the regression model. */ double r2(void) const; /** \f$s^2 \f$ is the estimation of variance of residuals or equivalently the conditional variance of Y. @return Conditional variance of Y */ virtual double s2(double w=1) const=0; /** The standard error is defined as \f$E((Y|x,w - \hat{y}(x))^2) \f$ @return error of model value in @a x */ virtual double standard_error2(const double x) const=0; protected: /// /// Averager for pair of x and y /// statistics::AveragerPairWeighted ap_; /** @brief Chi-squared Chi-squared is defined as the \f$\sum{w_i(\hat{y_i}-y_i)^2} \f$ */ double chisq_; private: }; }}} // of namespaces regression, yat, and theplu #endif