# Changeset 1643 for trunk/yat/regression/GSLInterpolation.h

Ignore:
Timestamp:
Dec 13, 2008, 1:23:39 AM (13 years ago)
Message:

Addresses #466 and #425. Added cubic spline interpolation (not complete interface to GSL interpolation stuff).

File:
1 copied

### Legend:

Unmodified
 r1637 #ifndef _theplu_yat_regression_linear_ #define _theplu_yat_regression_linear_ #ifndef _theplu_yat_regression_gslinterpolation_ #define _theplu_yat_regression_gslinterpolation_ // $Id$ /* Copyright (C) 2004, 2005, 2006, 2007 Jari Häkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson Copyright (C) 2008 Jari Häkkinen This file is part of the yat library, http://dev.thep.lu.se/yat */ #include "OneDimensional.h" #include #include namespace theplu { namespace yat { namespace utility { class VectorBase; } namespace utility { class VectorConstView; } namespace regression { /** @brief linear regression. Data are modeled as \f$y_i = \alpha + \beta (x_i-m_x) + \epsilon_i \f$. @brief Documentation please. */ class Linear : public OneDimensional { public: /// /// @brief The default constructor /// Linear(void); class GSLInterpolation { /// /// @brief The destructor /// virtual ~Linear(void); /** The parameter \f$\alpha \f$ is estimated as \f$\frac{1}{n}\sum y_i \f$ @return the parameter \f$\alpha \f$ */ double alpha(void) const; public: /** The standard deviation is estimated as \f$\sqrt{\frac{s^2}{n}} \f$ where \f$s^2 = \frac{\sum \epsilon^2}{n-2} \f$ @return standard deviation of parameter \f$\alpha \f$ @brief Documentation please. */ double alpha_var(void) const; double evaluate(const double x) const; protected: /** @brief The default constructor */ GSLInterpolation(const gsl_interp_type*, const utility::VectorConstView& x, const utility::VectorConstView& y); /** The parameter \f$\beta \f$ is estimated as \f$\frac{\textrm{Cov}(x,y)}{\textrm{Var}(x)} \f$ @return the parameter \f$\beta \f$ @brief The destructor */ double beta(void) const; virtual ~GSLInterpolation(void); private: /** The standard deviation is estimated as \f$\frac{s^2}{\sum (x-m_x)^2} \f$ where \f$s^2 = \frac{\sum \epsilon^2}{n-2} \f$ Copy Constructor. (not implemented) */ GSLInterpolation(const GSLInterpolation&); @return standard deviation of parameter \f$\beta \f$ */ double beta_var(void) const; /** Model is fitted by minimizing \f$\sum{(y_i - \alpha - \beta (x-m_x))^2} \f$. By construction \f$\alpha \f$ and \f$\beta \f$ are independent. */ void fit(const utility::VectorBase& x, const utility::VectorBase& y) ; /// /// @return \f$\alpha + \beta x \f$ /// double predict(const double x) const; /** \f$\frac{\sum \epsilon_i^2}{N-2} \f$ @return variance of residuals */ double s2(void) const; /** The error of the model is estimated as \f$\textrm{alpha\_err}^2+\textrm{beta\_err}^2*(x-m_x)*(x-m_x)\f$ @return estimated error of model in @a x */ double standard_error2(const double x) const; private: /// /// Copy Constructor. (not implemented) /// Linear(const Linear&); double alpha_; double alpha_var_; double beta_; double beta_var_; gsl_interp_accel* accelerator_; gsl_interp* interpolator_; double* x_; double* y_; };