#ifndef _theplu_yat_regression_gslinterpolation_ #define _theplu_yat_regression_gslinterpolation_ // \$Id: GSLInterpolation.h 1654 2008-12-16 16:29:35Z peter \$ /* Copyright (C) 2008 Jari Häkkinen 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 namespace theplu { namespace yat { namespace utility { class VectorBase; } namespace regression { /** \brief Base class for interfacing GSL interpolation. The GSL interpolation is described in the GSL Manual. The GSL library provides a variety of interpolation methods, including Cubic splines and Akima splines. Interpolations can be defined for both normal and periodic boundary conditions. Additional functions are available for computing derivatives and integrals of interpolating functions. Given a set of data points \f\$ (x_1, y_1) \dots (x_n, y_n) \f\$ the sub classes compute a continuous interpolating function \f\$ y(x) \f\$ such that \f\$ y(x_i) = y_i \f\$. The interpolation is piecewise smooth, and its behavior at the end-points is determined by the type of interpolation used. Some underlying GSL functions return GSL error codes. The error code is stored internally and should be checked for by the caller using GSLInterpolation::error_status(void). Refer to the gsl_errno.h for the error code listing. \since New in yat 0.5 */ class GSLInterpolation { public: /** \brief Search index. This function returns the index \f\$ i \f\$ of the array \a x_array such that \f\$ x_array[i] <= x < x_array[i+1] \f\$. The index is searched for in the range \f\$ [index_lo, index_hi] \f\$. */ size_t bsearch(const double x_array[], double x, size_t index_lo, size_t index_hi) const; /** \brief Check the error status Some underlying GSL functions return GSL error codes. The error code is stored internally and should be checked for by the caller. Refer to the gsl_errno.h for the error code listing. \return The current error status. A zero return values indicates no errors where encountered. */ int error_status(void) const; /** \brief Calculate the interpolated value for \a x. GSL error status is set if evaluation is requested outside the range defined by the interpolation algorithm. Use function error_status to check for errors. \return The interpolated value of \f\$ y \f\$ for a given point \a x. \see error_status(void) */ double evaluate(double x); /** \brief Calculate the derivative of the interpolated function at \a x. GSL error status is set if evaluation is requested outside the range defined by the interpolation algorithm. Use function error_status to check for errors. \return The derivative. \see error_status(void) */ double evaluate_derivative(double x); /** \brief Calculate the 2nd derivative of the interpolated function at \a x. GSL error status is set if evaluation is requested outside the range defined by the interpolation algorithm. Use function error_status to check for errors. \return The 2nd derivative. \see error_status(void) */ double evaluate_derivative2(double x); /** \brief Calculate the numerical integral of the interpolated function over the range \f\$ [a,b] \f\$. GSL error status is set if evaluation is requested outside the range defined by the interpolation algorithm. Use function error_status to check for errors. \return The integral. \see error_status(void) */ double evaluate_integral(double a, double b); /** \brief The result of the latest evaluaion function call is stored and can be retrieved with this function. \return The latest evaluated value. */ double evaluation(void) const; /** \brief This function returns the minimum number of points required by the interpolation type. For example, Akima spline interpolation requires a minimum of 5 points. \return The minimum number of points required. */ unsigned int min_size(void) const; protected: /** \brief The default constructor Initialization of the interpolation object for the data \f\$ (x, y) \f\$ where \a x and \a y are vector like objects of the same size. The content of \a x and \a y are copied for internal storage. \a x is always assumed to be strictly ordered, with increasing \a x values; the behavior for other arrangements is not defined. Some underlying GSL functions return GSL error codes. The error code is stored internally and should be checked for by the caller. Refer to the gsl_errno.h for the error code listing. \see error_status(void) */ GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x, const utility::VectorBase& y); /** \brief The destructor */ virtual ~GSLInterpolation(void); private: /** \brief Copy Constructor. (not implemented) */ GSLInterpolation(const GSLInterpolation&); gsl_interp_accel* accelerator_; double evaluation_; gsl_interp* interpolator_; int gsl_status_; double* x_; double* y_; }; }}} // of namespaces regression, yat, and theplu #endif