1643 |
13 Dec 08 |
jari |
1 |
#ifndef _theplu_yat_regression_gslinterpolation_ |
1643 |
13 Dec 08 |
jari |
2 |
#define _theplu_yat_regression_gslinterpolation_ |
193 |
27 Oct 04 |
peter |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
616 |
31 Aug 06 |
jari |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2004, 2005, 2006 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2009 Jari Häkkinen |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2022 Peter Johansson |
193 |
27 Oct 04 |
peter |
12 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
14 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
19 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
24 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
27 |
*/ |
675 |
10 Oct 06 |
jari |
28 |
|
4187 |
18 Jul 22 |
peter |
29 |
#include <memory> |
4187 |
18 Jul 22 |
peter |
30 |
|
1643 |
13 Dec 08 |
jari |
31 |
#include <gsl/gsl_interp.h> |
675 |
10 Oct 06 |
jari |
32 |
|
193 |
27 Oct 04 |
peter |
33 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
34 |
namespace yat { |
1643 |
13 Dec 08 |
jari |
35 |
namespace utility { |
1644 |
13 Dec 08 |
jari |
36 |
class VectorBase; |
1643 |
13 Dec 08 |
jari |
37 |
} |
383 |
12 Aug 05 |
jari |
38 |
namespace regression { |
383 |
12 Aug 05 |
jari |
39 |
|
713 |
21 Dec 06 |
peter |
40 |
/** |
1644 |
13 Dec 08 |
jari |
\brief Base class for interfacing GSL interpolation. |
1644 |
13 Dec 08 |
jari |
42 |
|
1654 |
16 Dec 08 |
peter |
The GSL interpolation is described in the |
1654 |
16 Dec 08 |
peter |
<A HREF= |
1654 |
16 Dec 08 |
peter |
"http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html"> |
1654 |
16 Dec 08 |
peter |
GSL Manual.</A> |
1654 |
16 Dec 08 |
peter |
The GSL library provides a variety of interpolation methods, |
1644 |
13 Dec 08 |
jari |
including Cubic splines and Akima splines. Interpolations can be |
1644 |
13 Dec 08 |
jari |
defined for both normal and periodic boundary |
1644 |
13 Dec 08 |
jari |
conditions. Additional functions are available for computing |
1644 |
13 Dec 08 |
jari |
derivatives and integrals of interpolating functions. |
1644 |
13 Dec 08 |
jari |
52 |
|
1644 |
13 Dec 08 |
jari |
Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$ |
1650 |
14 Dec 08 |
jari |
the sub classes compute a continuous interpolating function \f$ |
1644 |
13 Dec 08 |
jari |
y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is |
1644 |
13 Dec 08 |
jari |
piecewise smooth, and its behavior at the end-points is |
1644 |
13 Dec 08 |
jari |
determined by the type of interpolation used. |
1650 |
14 Dec 08 |
jari |
58 |
|
1724 |
15 Jan 09 |
jari |
When underlying GSL functions return GSL error an GSL_error is |
1724 |
15 Jan 09 |
jari |
thrown. Refer to the gsl_errno.h for the error code listing. |
1652 |
16 Dec 08 |
jari |
61 |
|
1652 |
16 Dec 08 |
jari |
\since New in yat 0.5 |
713 |
21 Dec 06 |
peter |
63 |
*/ |
1643 |
13 Dec 08 |
jari |
64 |
class GSLInterpolation |
1643 |
13 Dec 08 |
jari |
65 |
{ |
193 |
27 Oct 04 |
peter |
66 |
|
1643 |
13 Dec 08 |
jari |
67 |
public: |
1648 |
13 Dec 08 |
jari |
68 |
/** |
1722 |
15 Jan 09 |
jari |
\brief The default constructor |
1722 |
15 Jan 09 |
jari |
70 |
|
1722 |
15 Jan 09 |
jari |
Initialization of the interpolation object for the data \f$ (x, |
1722 |
15 Jan 09 |
jari |
y) \f$ where \a x and \a y are vector like objects of the same |
1722 |
15 Jan 09 |
jari |
size. The content of \a x and \a y are copied for internal |
1722 |
15 Jan 09 |
jari |
storage. \a x is always assumed to be strictly ordered, with |
1722 |
15 Jan 09 |
jari |
increasing \a x values; the behavior for other arrangements is |
1722 |
15 Jan 09 |
jari |
not defined. |
1722 |
15 Jan 09 |
jari |
77 |
|
1724 |
15 Jan 09 |
jari |
\throw GSL_error if some underlying GSL functions return GSL |
1724 |
15 Jan 09 |
jari |
error. Refer to gsl_errno.h for the error code listing. |
1722 |
15 Jan 09 |
jari |
80 |
*/ |
1722 |
15 Jan 09 |
jari |
81 |
GSLInterpolation(const gsl_interp_type*, const utility::VectorBase& x, |
1722 |
15 Jan 09 |
jari |
82 |
const utility::VectorBase& y); |
1722 |
15 Jan 09 |
jari |
83 |
|
1722 |
15 Jan 09 |
jari |
84 |
/** |
1661 |
18 Dec 08 |
peter |
\brief The destructor |
1661 |
18 Dec 08 |
peter |
86 |
*/ |
1661 |
18 Dec 08 |
peter |
87 |
virtual ~GSLInterpolation(void)=0; |
1661 |
18 Dec 08 |
peter |
88 |
|
1661 |
18 Dec 08 |
peter |
89 |
/** |
1644 |
13 Dec 08 |
jari |
\brief Calculate the interpolated value for \a x. |
1644 |
13 Dec 08 |
jari |
91 |
|
1644 |
13 Dec 08 |
jari |
\return The interpolated value of \f$ y \f$ for a given point |
1644 |
13 Dec 08 |
jari |
\a x. |
1650 |
14 Dec 08 |
jari |
94 |
|
1724 |
15 Jan 09 |
jari |
\throw GSL_error if evaluation is requested outside the range |
1724 |
15 Jan 09 |
jari |
defined by the interpolation algorithm. |
713 |
21 Dec 06 |
peter |
97 |
*/ |
1648 |
13 Dec 08 |
jari |
98 |
double evaluate(double x); |
193 |
27 Oct 04 |
peter |
99 |
|
1648 |
13 Dec 08 |
jari |
100 |
/** |
1648 |
13 Dec 08 |
jari |
\brief Calculate the derivative of the interpolated function at |
1648 |
13 Dec 08 |
jari |
\a x. |
1648 |
13 Dec 08 |
jari |
103 |
|
1648 |
13 Dec 08 |
jari |
\return The derivative. |
1650 |
14 Dec 08 |
jari |
105 |
|
1724 |
15 Jan 09 |
jari |
\throw GSL_error if evaluation is requested outside the range |
1724 |
15 Jan 09 |
jari |
defined by the interpolation algorithm. |
1648 |
13 Dec 08 |
jari |
108 |
*/ |
1648 |
13 Dec 08 |
jari |
109 |
double evaluate_derivative(double x); |
1648 |
13 Dec 08 |
jari |
110 |
|
1648 |
13 Dec 08 |
jari |
111 |
/** |
1648 |
13 Dec 08 |
jari |
\brief Calculate the 2nd derivative of the interpolated |
1648 |
13 Dec 08 |
jari |
function at \a x. |
1648 |
13 Dec 08 |
jari |
114 |
|
1648 |
13 Dec 08 |
jari |
\return The 2nd derivative. |
1650 |
14 Dec 08 |
jari |
116 |
|
1724 |
15 Jan 09 |
jari |
\throw GSL_error if evaluation is requested outside the range |
1724 |
15 Jan 09 |
jari |
defined by the interpolation algorithm. |
1648 |
13 Dec 08 |
jari |
119 |
*/ |
1648 |
13 Dec 08 |
jari |
120 |
double evaluate_derivative2(double x); |
1648 |
13 Dec 08 |
jari |
121 |
|
1648 |
13 Dec 08 |
jari |
122 |
/** |
1648 |
13 Dec 08 |
jari |
\brief Calculate the numerical integral of the interpolated |
1648 |
13 Dec 08 |
jari |
function over the range \f$ [a,b] \f$. |
1648 |
13 Dec 08 |
jari |
125 |
|
1648 |
13 Dec 08 |
jari |
\return The integral. |
1650 |
14 Dec 08 |
jari |
127 |
|
1724 |
15 Jan 09 |
jari |
\throw GSL_error if evaluation is requested outside the range |
1724 |
15 Jan 09 |
jari |
defined by the interpolation algorithm. |
1648 |
13 Dec 08 |
jari |
130 |
*/ |
1648 |
13 Dec 08 |
jari |
131 |
double evaluate_integral(double a, double b); |
1648 |
13 Dec 08 |
jari |
132 |
|
1648 |
13 Dec 08 |
jari |
133 |
/** |
1650 |
14 Dec 08 |
jari |
\brief The result of the latest evaluaion function call is |
1650 |
14 Dec 08 |
jari |
stored and can be retrieved with this function. |
1650 |
14 Dec 08 |
jari |
136 |
|
1650 |
14 Dec 08 |
jari |
\return The latest evaluated value. |
1650 |
14 Dec 08 |
jari |
138 |
*/ |
1650 |
14 Dec 08 |
jari |
139 |
double evaluation(void) const; |
1650 |
14 Dec 08 |
jari |
140 |
|
1650 |
14 Dec 08 |
jari |
141 |
/** |
1648 |
13 Dec 08 |
jari |
\brief This function returns the minimum number of points |
1648 |
13 Dec 08 |
jari |
required by the interpolation type. |
1648 |
13 Dec 08 |
jari |
144 |
|
1648 |
13 Dec 08 |
jari |
For example, Akima spline interpolation requires a minimum of 5 |
1648 |
13 Dec 08 |
jari |
points. |
1648 |
13 Dec 08 |
jari |
147 |
|
1648 |
13 Dec 08 |
jari |
\return The minimum number of points required. |
1648 |
13 Dec 08 |
jari |
149 |
*/ |
1648 |
13 Dec 08 |
jari |
150 |
unsigned int min_size(void) const; |
1648 |
13 Dec 08 |
jari |
151 |
|
1643 |
13 Dec 08 |
jari |
152 |
private: |
713 |
21 Dec 06 |
peter |
153 |
/** |
1644 |
13 Dec 08 |
jari |
\brief Copy Constructor. (not implemented) |
713 |
21 Dec 06 |
peter |
155 |
*/ |
1643 |
13 Dec 08 |
jari |
156 |
GSLInterpolation(const GSLInterpolation&); |
1676 |
24 Dec 08 |
peter |
// no assignment |
1676 |
24 Dec 08 |
peter |
158 |
GSLInterpolation& operator=(const GSLInterpolation&); |
213 |
04 Nov 04 |
peter |
159 |
|
1643 |
13 Dec 08 |
jari |
160 |
gsl_interp_accel* accelerator_; |
1650 |
14 Dec 08 |
jari |
161 |
double evaluation_; |
1643 |
13 Dec 08 |
jari |
162 |
gsl_interp* interpolator_; |
4187 |
18 Jul 22 |
peter |
163 |
std::unique_ptr<double[]> x_; |
4187 |
18 Jul 22 |
peter |
164 |
std::unique_ptr<double[]> y_; |
193 |
27 Oct 04 |
peter |
165 |
}; |
193 |
27 Oct 04 |
peter |
166 |
|
681 |
11 Oct 06 |
jari |
167 |
}}} // of namespaces regression, yat, and theplu |
193 |
27 Oct 04 |
peter |
168 |
|
193 |
27 Oct 04 |
peter |
169 |
#endif |