# Changeset 1643 for trunk/yat/regression

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).

Location:
trunk/yat/regression
Files:
1 edited
4 copied

Unmodified
Removed
• ## trunk/yat/regression/CSpline.cc

 r1637 /* 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 "Linear.h" #include "yat/statistics/AveragerPair.h" #include "yat/utility/VectorBase.h" #include "CSpline.h" #include namespace theplu { namespace regression { Linear::Linear(void) : OneDimensional(), alpha_(0), alpha_var_(0), beta_(0), beta_var_(0) CSpline::CSpline(const utility::VectorConstView& x, const utility::VectorConstView& y) : GSLInterpolation(gsl_interp_cspline,x,y) { } Linear::~Linear(void) CSpline::~CSpline(void) { } double Linear::alpha(void) const { return alpha_; } double Linear::alpha_var(void) const { return alpha_var_; } double Linear::beta(void) const { return beta_; } double Linear::beta_var(void) const { return beta_var_; } void Linear::fit(const utility::VectorBase& x, const utility::VectorBase& y) { ap_.reset(); for (size_t i=0; i
• ## trunk/yat/regression/CSpline.h

 r1637 #ifndef _theplu_yat_regression_linear_ #define _theplu_yat_regression_linear_ #ifndef _theplu_yat_regression_cspline_ #define _theplu_yat_regression_cspline_ // $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 "GSLInterpolation.h" 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 CSpline : public GSLInterpolation { /// /// @brief The destructor /// virtual ~Linear(void); public: /** The parameter \f$\alpha \f$ is estimated as \f$\frac{1}{n}\sum y_i \f$ @return the parameter \f$\alpha \f$ @brief The default constructor */ double alpha(void) const; CSpline(const utility::VectorConstView& x, const utility::VectorConstView& y); /** 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 The destructor */ double alpha_var(void) const; ~CSpline(void); private: /** The parameter \f$\beta \f$ is estimated as \f$\frac{\textrm{Cov}(x,y)}{\textrm{Var}(x)} \f$ @return the parameter \f$\beta \f$ Copy Constructor. (not implemented) */ double beta(void) const; CSpline(const CSpline&); /** 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$ @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_; };
• ## trunk/yat/regression/GSLInterpolation.cc

 r1637 /* 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 "Linear.h" #include "yat/statistics/AveragerPair.h" #include "yat/utility/VectorBase.h" #include "GSLInterpolation.h" #include "yat/utility/VectorConstView.h" #include namespace theplu { namespace regression { Linear::Linear(void) : OneDimensional(), alpha_(0), alpha_var_(0), beta_(0), beta_var_(0) GSLInterpolation::GSLInterpolation(const gsl_interp_type* interpolator_type, const utility::VectorConstView& x, const utility::VectorConstView& y) { assert(x.size()==y.size()); size_t size=x.size(); x_=new double[size]; y_=new double[size]; for (size_t i=0; i
• ## trunk/yat/regression/GSLInterpolation.h

 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_; };
• ## trunk/yat/regression/Makefile.am

 r1493 # Copyright (C) 2006 Jari Häkkinen # Copyright (C) 2007 Jari Häkkinen, Peter Johansson # Copyright (C) 2008 Jari Häkkinen # # This file is part of the yat library, http://dev.thep.lu.se/yat noinst_LTLIBRARIES = libregression.la libregression_la_SOURCES = KernelBox.cc KernelTriCube.cc Linear.cc  \ libregression_la_SOURCES = CSpline.cc GSLInterpolation.cc KernelBox.cc \ KernelTriCube.cc Linear.cc  \ LinearWeighted.cc Local.cc MultiDimensional.cc      \ MultiDimensionalWeighted.cc Naive.cc NaiveWeighted.cc   \ include_regressiondir = \$(includedir)/yat/regression include_regression_HEADERS = Kernel.h KernelBox.h KernelTriCube.h \ include_regression_HEADERS = CSpline.h GSLInterpolation.h Kernel.h \ KernelBox.h KernelTriCube.h \ Linear.h LinearWeighted.h Local.h MultiDimensional.h    \ MultiDimensionalWeighted.h Naive.h NaiveWeighted.h    \
Note: See TracChangeset for help on using the changeset viewer.