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

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

Addresses #466. Moved default contructor to be public.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1#ifndef _theplu_yat_regression_gslinterpolation_
2#define _theplu_yat_regression_gslinterpolation_
3
4// $Id: GSLInterpolation.h 1722 2009-01-15 13:12:16Z jari $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009 Jari Häkkinen
9
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <gsl/gsl_interp.h>
27
28namespace theplu {
29namespace yat {
30namespace utility {
31  class VectorBase;
32}
33namespace regression {
34
35  /**
36     \brief Base class for interfacing GSL interpolation.
37
38     The GSL interpolation is described in the
39     <A HREF=
40     "http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html">
41     GSL Manual.</A>
42     The GSL library provides a variety of interpolation methods,
43     including Cubic splines and Akima splines. Interpolations can be
44     defined for both normal and periodic boundary
45     conditions. Additional functions are available for computing
46     derivatives and integrals of interpolating functions.
47
48     Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$
49     the sub classes compute a continuous interpolating function \f$
50     y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is
51     piecewise smooth, and its behavior at the end-points is
52     determined by the type of interpolation used.
53
54     Some underlying GSL functions return GSL error codes. The error
55     code is stored internally and should be checked for by the caller
56     using GSLInterpolation::error_status(void). Refer to the
57     gsl_errno.h for the error code listing.
58
59     \since New in yat 0.5
60  */
61  class GSLInterpolation
62  {
63
64  public:
65    /**
66       \brief The default constructor
67
68       Initialization of the interpolation object for the data \f$ (x,
69       y) \f$ where \a x and \a y are vector like objects of the same
70       size. The content of \a x and \a y are copied for internal
71       storage. \a x is always assumed to be strictly ordered, with
72       increasing \a x values; the behavior for other arrangements is
73       not defined.
74
75       Some underlying GSL functions return GSL error codes. The error
76       code is stored internally and should be checked for by the
77       caller. Refer to the gsl_errno.h for the error code listing.
78
79       \see error_status(void)
80    */
81    GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x,
82                     const utility::VectorBase& y);
83
84    /**
85       \brief The destructor
86    */
87    virtual ~GSLInterpolation(void)=0;
88
89    /**
90       \brief Check the error status
91
92       Some underlying GSL functions return GSL error codes. The error
93       code is stored internally and should be checked for by the
94       caller. Refer to the gsl_errno.h for the error code listing.
95
96       \return The current error status. A zero return values
97       indicates no errors where encountered.
98    */
99    int error_status(void) const;
100
101    /**
102       \brief Calculate the interpolated value for \a x.
103
104       GSL error status is set if evaluation is requested outside the
105       range defined by the interpolation algorithm. Use function
106       error_status to check for errors.
107
108       \return The interpolated value of \f$ y \f$ for a given point
109       \a x.
110
111       \see error_status(void)
112    */
113    double evaluate(double x);
114
115    /**
116       \brief Calculate the derivative of the interpolated function at
117       \a x.
118
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
123       \return The derivative.
124
125       \see error_status(void)
126    */
127    double evaluate_derivative(double x);
128
129    /**
130       \brief Calculate the 2nd derivative of the interpolated
131       function at \a x.
132
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
137       \return The 2nd derivative.
138
139       \see error_status(void)
140    */
141    double evaluate_derivative2(double x);
142
143    /**
144       \brief Calculate the numerical integral of the interpolated
145       function over the range \f$ [a,b] \f$.
146
147       GSL error status is set if evaluation is requested outside the
148       range defined by the interpolation algorithm. Use function
149       error_status to check for errors.
150
151       \return The integral.
152
153       \see error_status(void)
154    */
155    double evaluate_integral(double a, double b);
156
157    /**
158       \brief The result of the latest evaluaion function call is
159       stored and can be retrieved with this function.
160
161       \return The latest evaluated value.
162     */
163    double evaluation(void) const;
164
165    /**
166       \brief This function returns the minimum number of points
167       required by the interpolation type.
168
169       For example, Akima spline interpolation requires a minimum of 5
170       points.
171
172       \return The minimum number of points required.
173    */
174    unsigned int min_size(void) const;
175
176  private:
177    /**
178       \brief Copy Constructor. (not implemented)
179    */
180    GSLInterpolation(const GSLInterpolation&);
181    // no assignment
182    GSLInterpolation& operator=(const GSLInterpolation&);
183
184    gsl_interp_accel* accelerator_;
185    double evaluation_;
186    gsl_interp* interpolator_;
187    int gsl_status_;
188    double* x_;
189    double* y_;
190  };
191
192}}} // of namespaces regression, yat, and theplu
193
194#endif
Note: See TracBrowser for help on using the repository browser.