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

Last change on this file since 1652 was 1652, checked in by Jari Häkkinen, 14 years ago

Fixes #469. Added doxygen \since tag.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1#ifndef _theplu_yat_regression_gslinterpolation_
2#define _theplu_yat_regression_gslinterpolation_
3
4// $Id: GSLInterpolation.h 1652 2008-12-16 09:32:25Z jari $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
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
13  published by the Free Software Foundation; either version 3 of the
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
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include <gsl/gsl_interp.h>
26
27namespace theplu {
28namespace yat {
29namespace utility {
30  class VectorBase;
31}
32namespace regression {
33
34  /**
35     \brief Base class for interfacing GSL interpolation.
36
37     The GSL interpolation is described 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 classes compute 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.
50
51     Some underlying GSL functions return GSL error codes. The error
52     code is stored internally and should be checked for by the caller
53     using GSLInterpolation::error_status(void). Refer to the
54     gsl_errno.h for the error code listing.
55
56     \since New in yat 0.5
57  */
58  class GSLInterpolation
59  {
60
61  public:
62    /**
63       \brief Search index.
64
65       This function returns the index \f$ i \f$ of the array \a
66       x_array such that \f$ x_array[i] <= x < x_array[i+1] \f$. The
67       index is searched for in the range
68       \f$ [index_lo, index_hi] \f$.
69    */
70    size_t bsearch(const double x_array[], double x, size_t index_lo,
71                   size_t index_hi) const;
72
73    /**
74       \brief Check the error status
75
76       Some underlying GSL functions return GSL error codes. The error
77       code is stored internally and should be checked for by the
78       caller. Refer to the gsl_errno.h for the error code listing.
79
80       \return The current error status. A zero return values
81       indicates no errors where encountered.
82    */
83    int error_status(void) const;
84
85    /**
86       \brief Calculate the interpolated value for \a x.
87
88       GSL error status is set if evaluation is requested outside the
89       range defined by the interpolation algorithm. Use function
90       error_status to check for errors.
91
92       \return The interpolated value of \f$ y \f$ for a given point
93       \a x.
94
95       \see error_status(void)
96    */
97    double evaluate(double x);
98
99    /**
100       \brief Calculate the derivative of the interpolated function at
101       \a x.
102
103       GSL error status is set if evaluation is requested outside the
104       range defined by the interpolation algorithm. Use function
105       error_status to check for errors.
106
107       \return The derivative.
108
109       \see error_status(void)
110    */
111    double evaluate_derivative(double x);
112
113    /**
114       \brief Calculate the 2nd derivative of the interpolated
115       function at \a x.
116
117       GSL error status is set if evaluation is requested outside the
118       range defined by the interpolation algorithm. Use function
119       error_status to check for errors.
120
121       \return The 2nd derivative.
122
123       \see error_status(void)
124    */
125    double evaluate_derivative2(double x);
126
127    /**
128       \brief Calculate the numerical integral of the interpolated
129       function over the range \f$ [a,b] \f$.
130
131       GSL error status is set if evaluation is requested outside the
132       range defined by the interpolation algorithm. Use function
133       error_status to check for errors.
134
135       \return The integral.
136
137       \see error_status(void)
138    */
139    double evaluate_integral(double a, double b);
140
141    /**
142       \brief The result of the latest evaluaion function call is
143       stored and can be retrieved with this function.
144
145       \return The latest evaluated value.
146     */
147    double evaluation(void) const;
148
149    /**
150       \brief This function returns the minimum number of points
151       required by the interpolation type.
152
153       For example, Akima spline interpolation requires a minimum of 5
154       points.
155
156       \return The minimum number of points required.
157    */
158    unsigned int min_size(void) const;
159
160  protected:
161    /**
162       \brief The default constructor
163
164       Initialization of the interpolation object for the data \f$ (x,
165       y) \f$ where \a x and \a y are vector like objects of the same
166       size. The content of \a x and \a y are copied for internal
167       storage. \a x is always assumed to be strictly ordered, with
168       increasing \a x values; the behavior for other arrangements is
169       not defined.
170
171       Some underlying GSL functions return GSL error codes. The error
172       code is stored internally and should be checked for by the
173       caller. Refer to the gsl_errno.h for the error code listing.
174
175       \see error_status(void)
176    */
177    GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x,
178                     const utility::VectorBase& y);
179
180    /**
181       \brief The destructor
182    */
183    virtual ~GSLInterpolation(void);
184
185  private:
186    /**
187       \brief Copy Constructor. (not implemented)
188    */
189    GSLInterpolation(const GSLInterpolation&);
190
191    gsl_interp_accel* accelerator_;
192    double evaluation_;
193    gsl_interp* interpolator_;
194    int gsl_status_;
195    double* x_;
196    double* y_;
197  };
198
199}}} // of namespaces regression, yat, and theplu
200
201#endif
Note: See TracBrowser for help on using the repository browser.