[1643] | 1 | #ifndef _theplu_yat_regression_gslinterpolation_ |
---|
| 2 | #define _theplu_yat_regression_gslinterpolation_ |
---|
[193] | 3 | |
---|
[616] | 4 | // $Id: GSLInterpolation.h 1648 2008-12-13 09:28:39Z jari $ |
---|
| 5 | |
---|
[675] | 6 | /* |
---|
[1643] | 7 | Copyright (C) 2008 Jari Häkkinen |
---|
[193] | 8 | |
---|
[1437] | 9 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
[675] | 10 | |
---|
| 11 | The yat library is free software; you can redistribute it and/or |
---|
| 12 | modify it under the terms of the GNU General Public License as |
---|
[1486] | 13 | published by the Free Software Foundation; either version 3 of the |
---|
[675] | 14 | License, or (at your option) any later version. |
---|
| 15 | |
---|
| 16 | The yat library is distributed in the hope that it will be useful, |
---|
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 19 | General Public License for more details. |
---|
| 20 | |
---|
| 21 | You should have received a copy of the GNU General Public License |
---|
[1487] | 22 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
[675] | 23 | */ |
---|
| 24 | |
---|
[1643] | 25 | #include <gsl/gsl_interp.h> |
---|
[675] | 26 | |
---|
[193] | 27 | namespace theplu { |
---|
[680] | 28 | namespace yat { |
---|
[1643] | 29 | namespace utility { |
---|
[1644] | 30 | class VectorBase; |
---|
[1643] | 31 | } |
---|
[383] | 32 | namespace regression { |
---|
| 33 | |
---|
[713] | 34 | /** |
---|
[1644] | 35 | \brief Base class for interfacing GSL interpolation. |
---|
| 36 | |
---|
| 37 | The GSL interpolation is descibed in |
---|
| 38 | http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html. The |
---|
| 39 | GSL library provides a variety of interpolation methods, |
---|
| 40 | including Cubic splines and Akima splines. Interpolations can be |
---|
| 41 | defined for both normal and periodic boundary |
---|
| 42 | conditions. Additional functions are available for computing |
---|
| 43 | derivatives and integrals of interpolating functions. |
---|
| 44 | |
---|
| 45 | Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$ |
---|
| 46 | the sub classescompute a continuous interpolating function \f$ |
---|
| 47 | y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is |
---|
| 48 | piecewise smooth, and its behavior at the end-points is |
---|
| 49 | determined by the type of interpolation used. |
---|
[713] | 50 | */ |
---|
[1643] | 51 | class GSLInterpolation |
---|
| 52 | { |
---|
[193] | 53 | |
---|
[1643] | 54 | public: |
---|
[1648] | 55 | /** |
---|
| 56 | \brief Search index. |
---|
[216] | 57 | |
---|
[1648] | 58 | This function returns the index \f$ i \f$ of the array \a |
---|
| 59 | x_array such that \f$ x_array[i] <= x < x_array[i+1] \f$. The |
---|
| 60 | index is searched for in the range |
---|
| 61 | \f$ [index_lo, index_hi] \f$. |
---|
| 62 | */ |
---|
| 63 | size_t bsearch(const double x_array[], double x, size_t index_lo, |
---|
| 64 | size_t index_hi) const; |
---|
| 65 | |
---|
[713] | 66 | /** |
---|
[1644] | 67 | \brief Calculate the interpolated value for \a x. |
---|
| 68 | |
---|
| 69 | \return The interpolated value of \f$ y \f$ for a given point |
---|
| 70 | \a x. |
---|
[713] | 71 | */ |
---|
[1648] | 72 | double evaluate(double x); |
---|
[193] | 73 | |
---|
[1648] | 74 | /** |
---|
| 75 | \brief Calculate the derivative of the interpolated function at |
---|
| 76 | \a x. |
---|
| 77 | |
---|
| 78 | \return The derivative. |
---|
| 79 | */ |
---|
| 80 | double evaluate_derivative(double x); |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | \brief Calculate the 2nd derivative of the interpolated |
---|
| 84 | function at \a x. |
---|
| 85 | |
---|
| 86 | \return The 2nd derivative. |
---|
| 87 | */ |
---|
| 88 | double evaluate_derivative2(double x); |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | \brief Calculate the numerical integral of the interpolated |
---|
| 92 | function over the range \f$ [a,b] \f$. |
---|
| 93 | |
---|
| 94 | \return The integral. |
---|
| 95 | */ |
---|
| 96 | double evaluate_integral(double a, double b); |
---|
| 97 | |
---|
| 98 | /** |
---|
| 99 | \brief This function returns the minimum number of points |
---|
| 100 | required by the interpolation type. |
---|
| 101 | |
---|
| 102 | For example, Akima spline interpolation requires a minimum of 5 |
---|
| 103 | points. |
---|
| 104 | |
---|
| 105 | \return The minimum number of points required. |
---|
| 106 | */ |
---|
| 107 | unsigned int min_size(void) const; |
---|
| 108 | |
---|
[1643] | 109 | protected: |
---|
[713] | 110 | /** |
---|
[1644] | 111 | \brief The default constructor |
---|
| 112 | |
---|
| 113 | Initializion of the interpolation object for the data \f$ (x, |
---|
| 114 | y) \f$ where \a x and \a y are vector like objects of the same |
---|
| 115 | size. The content of \a x and \a y are copied for internal |
---|
| 116 | storage. \a x is always assumed to be strictly ordered, with |
---|
| 117 | increasing \a x values; the behavior for other arrangements is |
---|
| 118 | not defined. |
---|
[713] | 119 | */ |
---|
[1644] | 120 | GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x, |
---|
| 121 | const utility::VectorBase& y); |
---|
[207] | 122 | |
---|
[713] | 123 | /** |
---|
[1644] | 124 | \brief The destructor |
---|
[713] | 125 | */ |
---|
[1643] | 126 | virtual ~GSLInterpolation(void); |
---|
[718] | 127 | |
---|
[1643] | 128 | private: |
---|
[713] | 129 | /** |
---|
[1644] | 130 | \brief Copy Constructor. (not implemented) |
---|
[713] | 131 | */ |
---|
[1643] | 132 | GSLInterpolation(const GSLInterpolation&); |
---|
[213] | 133 | |
---|
[1643] | 134 | gsl_interp_accel* accelerator_; |
---|
| 135 | gsl_interp* interpolator_; |
---|
| 136 | double* x_; |
---|
| 137 | double* y_; |
---|
[193] | 138 | }; |
---|
| 139 | |
---|
[681] | 140 | }}} // of namespaces regression, yat, and theplu |
---|
[193] | 141 | |
---|
| 142 | #endif |
---|