yat/regression/GSLInterpolation.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
616 31 Aug 06 jari 5
675 10 Oct 06 jari 6 /*
4359 23 Aug 23 peter 7   Copyright (C) 2004, 2005, 2006 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2007 Peter Johansson
4359 23 Aug 23 peter 9   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
2119 12 Dec 09 peter 10   Copyright (C) 2009 Jari Häkkinen
4207 26 Aug 22 peter 11   Copyright (C) 2022 Peter Johansson
193 27 Oct 04 peter 12
1437 25 Aug 08 peter 13   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 15   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 16   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 17   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 18   License, or (at your option) any later version.
675 10 Oct 06 jari 19
675 10 Oct 06 jari 20   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 21   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 23   General Public License for more details.
675 10 Oct 06 jari 24
675 10 Oct 06 jari 25   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 26   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 41      \brief Base class for interfacing GSL interpolation.
1644 13 Dec 08 jari 42
1654 16 Dec 08 peter 43      The GSL interpolation is described in the
1654 16 Dec 08 peter 44      <A HREF=
1654 16 Dec 08 peter 45      "http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html">
1654 16 Dec 08 peter 46      GSL Manual.</A>
1654 16 Dec 08 peter 47      The GSL library provides a variety of interpolation methods,
1644 13 Dec 08 jari 48      including Cubic splines and Akima splines. Interpolations can be
1644 13 Dec 08 jari 49      defined for both normal and periodic boundary
1644 13 Dec 08 jari 50      conditions. Additional functions are available for computing
1644 13 Dec 08 jari 51      derivatives and integrals of interpolating functions.
1644 13 Dec 08 jari 52
1644 13 Dec 08 jari 53      Given a set of data points \f$ (x_1, y_1) \dots (x_n, y_n) \f$
1650 14 Dec 08 jari 54      the sub classes compute a continuous interpolating function \f$
1644 13 Dec 08 jari 55      y(x) \f$ such that \f$ y(x_i) = y_i \f$. The interpolation is
1644 13 Dec 08 jari 56      piecewise smooth, and its behavior at the end-points is
1644 13 Dec 08 jari 57      determined by the type of interpolation used.
1650 14 Dec 08 jari 58
1724 15 Jan 09 jari 59      When underlying GSL functions return GSL error an GSL_error is
1724 15 Jan 09 jari 60      thrown. Refer to the gsl_errno.h for the error code listing.
1652 16 Dec 08 jari 61
1652 16 Dec 08 jari 62      \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 69        \brief The default constructor
1722 15 Jan 09 jari 70
1722 15 Jan 09 jari 71        Initialization of the interpolation object for the data \f$ (x,
1722 15 Jan 09 jari 72        y) \f$ where \a x and \a y are vector like objects of the same
1722 15 Jan 09 jari 73        size. The content of \a x and \a y are copied for internal
1722 15 Jan 09 jari 74        storage. \a x is always assumed to be strictly ordered, with
1722 15 Jan 09 jari 75        increasing \a x values; the behavior for other arrangements is
1722 15 Jan 09 jari 76        not defined.
1722 15 Jan 09 jari 77
1724 15 Jan 09 jari 78        \throw GSL_error if some underlying GSL functions return GSL
1724 15 Jan 09 jari 79        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 85        \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 90        \brief Calculate the interpolated value for \a x.
1644 13 Dec 08 jari 91
1644 13 Dec 08 jari 92        \return The interpolated value of \f$ y \f$ for a given point
1644 13 Dec 08 jari 93        \a x.
1650 14 Dec 08 jari 94
1724 15 Jan 09 jari 95        \throw GSL_error if evaluation is requested outside the range
1724 15 Jan 09 jari 96        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 101        \brief Calculate the derivative of the interpolated function at
1648 13 Dec 08 jari 102        \a x.
1648 13 Dec 08 jari 103
1648 13 Dec 08 jari 104        \return The derivative.
1650 14 Dec 08 jari 105
1724 15 Jan 09 jari 106        \throw GSL_error if evaluation is requested outside the range
1724 15 Jan 09 jari 107        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 112        \brief Calculate the 2nd derivative of the interpolated
1648 13 Dec 08 jari 113        function at \a x.
1648 13 Dec 08 jari 114
1648 13 Dec 08 jari 115        \return The 2nd derivative.
1650 14 Dec 08 jari 116
1724 15 Jan 09 jari 117        \throw GSL_error if evaluation is requested outside the range
1724 15 Jan 09 jari 118        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 123        \brief Calculate the numerical integral of the interpolated
1648 13 Dec 08 jari 124        function over the range \f$ [a,b] \f$.
1648 13 Dec 08 jari 125
1648 13 Dec 08 jari 126        \return The integral.
1650 14 Dec 08 jari 127
1724 15 Jan 09 jari 128        \throw GSL_error if evaluation is requested outside the range
1724 15 Jan 09 jari 129        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 134        \brief The result of the latest evaluaion function call is
1650 14 Dec 08 jari 135        stored and can be retrieved with this function.
1650 14 Dec 08 jari 136
1650 14 Dec 08 jari 137        \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 142        \brief This function returns the minimum number of points
1648 13 Dec 08 jari 143        required by the interpolation type.
1648 13 Dec 08 jari 144
1648 13 Dec 08 jari 145        For example, Akima spline interpolation requires a minimum of 5
1648 13 Dec 08 jari 146        points.
1648 13 Dec 08 jari 147
1648 13 Dec 08 jari 148        \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 154        \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 157     // 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