source: trunk/yat/regression/GSLInterpolation.h @ 1654

Last change on this file since 1654 was 1654, checked in by Peter, 13 years ago

fixing what I tried to fix in [1653]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
RevLine 
[1643]1#ifndef _theplu_yat_regression_gslinterpolation_
2#define _theplu_yat_regression_gslinterpolation_
[193]3
[616]4// $Id: GSLInterpolation.h 1654 2008-12-16 16:29:35Z peter $
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]27namespace theplu {
[680]28namespace yat {
[1643]29namespace utility {
[1644]30  class VectorBase;
[1643]31}
[383]32namespace regression {
33
[713]34  /**
[1644]35     \brief Base class for interfacing GSL interpolation.
36
[1654]37     The GSL interpolation is described in the
38     <A HREF=
39     "http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html">
40     GSL Manual.</A>
41     The GSL library provides a variety of interpolation methods,
[1644]42     including Cubic splines and Akima splines. Interpolations can be
43     defined for both normal and periodic boundary
44     conditions. Additional functions are available for computing
45     derivatives and integrals of interpolating functions.
46
47     Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$
[1650]48     the sub classes compute a continuous interpolating function \f$
[1644]49     y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is
50     piecewise smooth, and its behavior at the end-points is
51     determined by the type of interpolation used.
[1650]52
53     Some underlying GSL functions return GSL error codes. The error
54     code is stored internally and should be checked for by the caller
55     using GSLInterpolation::error_status(void). Refer to the
56     gsl_errno.h for the error code listing.
[1652]57
58     \since New in yat 0.5
[713]59  */
[1643]60  class GSLInterpolation
61  {
[193]62
[1643]63  public:
[1648]64    /**
65       \brief Search index.
[216]66
[1648]67       This function returns the index \f$ i \f$ of the array \a
68       x_array such that \f$ x_array[i] <= x < x_array[i+1] \f$. The
69       index is searched for in the range
70       \f$ [index_lo, index_hi] \f$.
71    */
72    size_t bsearch(const double x_array[], double x, size_t index_lo,
73                   size_t index_hi) const;
74
[713]75    /**
[1650]76       \brief Check the error status
77
78       Some underlying GSL functions return GSL error codes. The error
79       code is stored internally and should be checked for by the
80       caller. Refer to the gsl_errno.h for the error code listing.
81
82       \return The current error status. A zero return values
83       indicates no errors where encountered.
84    */
85    int error_status(void) const;
86
87    /**
[1644]88       \brief Calculate the interpolated value for \a x.
89
[1650]90       GSL error status is set if evaluation is requested outside the
91       range defined by the interpolation algorithm. Use function
92       error_status to check for errors.
93
[1644]94       \return The interpolated value of \f$ y \f$ for a given point
95       \a x.
[1650]96
97       \see error_status(void)
[713]98    */
[1648]99    double evaluate(double x);
[193]100
[1648]101    /**
102       \brief Calculate the derivative of the interpolated function at
103       \a x.
104
[1650]105       GSL error status is set if evaluation is requested outside the
106       range defined by the interpolation algorithm. Use function
107       error_status to check for errors.
108
[1648]109       \return The derivative.
[1650]110
111       \see error_status(void)
[1648]112    */
113    double evaluate_derivative(double x);
114
115    /**
116       \brief Calculate the 2nd derivative of the interpolated
117       function at \a x.
118
[1650]119       GSL error status is set if evaluation is requested outside the
120       range defined by the interpolation algorithm. Use function
121       error_status to check for errors.
122
[1648]123       \return The 2nd derivative.
[1650]124
125       \see error_status(void)
[1648]126    */
127    double evaluate_derivative2(double x);
128
129    /**
130       \brief Calculate the numerical integral of the interpolated
131       function over the range \f$ [a,b] \f$.
132
[1650]133       GSL error status is set if evaluation is requested outside the
134       range defined by the interpolation algorithm. Use function
135       error_status to check for errors.
136
[1648]137       \return The integral.
[1650]138
139       \see error_status(void)
[1648]140    */
141    double evaluate_integral(double a, double b);
142
143    /**
[1650]144       \brief The result of the latest evaluaion function call is
145       stored and can be retrieved with this function.
146
147       \return The latest evaluated value.
148     */
149    double evaluation(void) const;
150
151    /**
[1648]152       \brief This function returns the minimum number of points
153       required by the interpolation type.
154
155       For example, Akima spline interpolation requires a minimum of 5
156       points.
157
158       \return The minimum number of points required.
159    */
160    unsigned int min_size(void) const;
161
[1643]162  protected:
[713]163    /**
[1644]164       \brief The default constructor
165
[1650]166       Initialization of the interpolation object for the data \f$ (x,
[1644]167       y) \f$ where \a x and \a y are vector like objects of the same
168       size. The content of \a x and \a y are copied for internal
169       storage. \a x is always assumed to be strictly ordered, with
170       increasing \a x values; the behavior for other arrangements is
171       not defined.
[1650]172
173       Some underlying GSL functions return GSL error codes. The error
174       code is stored internally and should be checked for by the
175       caller. Refer to the gsl_errno.h for the error code listing.
176
177       \see error_status(void)
[713]178    */
[1644]179    GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x,
180                     const utility::VectorBase& y);
[207]181
[713]182    /**
[1644]183       \brief The destructor
[713]184    */
[1643]185    virtual ~GSLInterpolation(void);
[718]186
[1643]187  private:
[713]188    /**
[1644]189       \brief Copy Constructor. (not implemented)
[713]190    */
[1643]191    GSLInterpolation(const GSLInterpolation&);
[213]192
[1643]193    gsl_interp_accel* accelerator_;
[1650]194    double evaluation_;
[1643]195    gsl_interp* interpolator_;
[1650]196    int gsl_status_;
[1643]197    double* x_;
198    double* y_;
[193]199  };
200
[681]201}}} // of namespaces regression, yat, and theplu
[193]202
203#endif
Note: See TracBrowser for help on using the repository browser.