Loading...
Searching...
No Matches
casacore::Chebyshev< T > Class Template Reference
scimath package (libcasa_scimath) » Functionals_module

More...

`#include <Chebyshev.h>`

## Public Member Functions

| Chebyshev ()
| create a zero-th order Chebyshev polynomial with the first coefficient equal to zero.
| Chebyshev (const uInt n)
| create an n-th order Chebyshev polynomial with the coefficients equal to zero.
| Chebyshev (const T &min, const T &max, const typename ChebyshevEnums::OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, const T &defval=T(0))
| create a zero-th order Chebyshev polynomical with the first coefficient equal to one.
| Chebyshev (const Vector< T > &coeffs, const T &min, const T &max, const typename ChebyshevEnums::OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, const T &defval=T(0))
| create a fully specified Chebyshev polynomial.
| Chebyshev (uInt order, const RecordInterface &mode)
| create a fully specified Chebyshev polynomial.
| Chebyshev (const Vector< T > &coeffs, const RecordInterface &mode)
| Chebyshev (const Chebyshev &other)
| create a deep copy of another Chebyshev polynomial
Chebyshev< T > & | operator= (const Chebyshev< T > &other)
| make this instance a (deep) copy of another Chebyshev polynomial
virtual | ~Chebyshev ()
| Destructor.
virtual T | eval (const typename FunctionTraits< T >::ArgType *x) const
| Evaluate the Chebyshev at x.
Chebyshev< T > | derivative () const
| Return the Chebyshev polynomial which is the derivative of this one (with respect to the argument x).
virtual Function< T > * | clone () const
| Create a new copy of this object.
Public Member Functions inherited from casacore::ChebyshevParamModeImpl< T >
| ChebyshevParamModeImpl ()
| ChebyshevParamModeImpl (const uInt n)
| ChebyshevParamModeImpl (const T &min, const T &max, typename ChebyshevEnums::OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, const T &defval=T(0))
| ChebyshevParamModeImpl (const Vector< T > &coeffs, const T &min, const T &max, typename ChebyshevEnums::OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, const T &defval=T(0))
| ChebyshevParamModeImpl (uInt order, const RecordInterface &mode)
| ChebyshevParamModeImpl (const Vector< T > &coeffs, const RecordInterface &mode)
| ChebyshevParamModeImpl (const ChebyshevParamModeImpl &other)
virtual void | setMode (const RecordInterface &mode)
| get/set the function mode.
virtual void | getMode (RecordInterface &mode) const
virtual Bool | hasMode () const
| return True if the implementing function supports a mode.
Public Member Functions inherited from casacore::ChebyshevParam< T >
| ChebyshevParam ()
| create a zero-th order Chebyshev polynomial with the first coefficient equal to zero.
| ChebyshevParam (const uInt n)
| create an n-th order Chebyshev polynomial with the coefficients equal to zero.
| ChebyshevParam (const T &min, const T &max, ChebyshevEnums::OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, const T &defval=T(0))
| create a zero-th order Chebyshev polynomical with the first coefficient equal to one.
| ChebyshevParam (const Vector< T > &coeffs, const T &min, const T &max, ChebyshevEnums::OutOfIntervalMode mode=ChebyshevEnums::CONSTANT, const T &defval=T(0))
| create a fully specified Chebyshev polynomial.
| ChebyshevParam (uInt order, const RecordInterface &mode)
| create a fully specified Chebyshev polynomial.
| ChebyshevParam (const Vector< T > &coeffs, const RecordInterface &mode)
| ChebyshevParam (const ChebyshevParam &other)
| create a deep copy of another Chebyshev polynomial
template<class W>
| ChebyshevParam (const ChebyshevParam< W > &other)
ChebyshevParam< T > & | operator= (const ChebyshevParam< T > &other)
| make a (deep) copy of another Chebyshev polynomial
virtual | ~ChebyshevParam ()
| Destructor.
void | setCoefficients (const Vector< T > &coeffs)
| set the Chebyshev coefficients.
void | setCoefficient (const uInt which, const T &value)
| set a particular Chebyshev coefficient.
const Vector< T > & | getCoefficients () const
| return the current set of coefficients into a given Vector.
T | getCoefficient (const uInt which) const
| return a particular coefficient.
uInt | nCoefficients () const
| return the number of coeefficients currently loaded.
void | setInterval (T xmin, T xmax)
| set the Chebyshev interval for this function.
T | getIntervalMin () const
| return the minimum value for the currently Chebyshev interval.
T | getIntervalMax () const
| return the maximum value for the currently Chebyshev interval.
void | setOutOfIntervalMode (ChebyshevEnums::OutOfIntervalMode mode)
| set the behavior of this function when it is evaluated outside its Chebyshev interval
ChebyshevEnums::OutOfIntervalMode | getOutOfIntervalMode () const
| return the behavior of this function when it is evaluated outside of its Chebyshev interval.
void | setDefault (const T &val)
| set the default value of this function.
const T & | getDefault () const
| return the currently set default value.
uInt | order () const
| return the order of this polynomial.
virtual const String & | name () const
| Give name of function.
Public Member Functions inherited from casacore::Function1D< T, U >
| Function1D ()
| Constructors.
| Function1D (const uInt n)
| Function1D (const Vector< T > &in)
| Function1D (const FunctionParam< T > &other)
template<class W, class X>
| Function1D (const Function1D< W, X > &other)
virtual | ~Function1D ()
| Destructor.
virtual uInt | ndim () const
| Returns the number of dimensions of function.
Public Member Functions inherited from casacore::Function< T, T >
| Function ()
| Constructors.
virtual | ~Function ()
| Destructor.
uInt | nparameters () const
| Returns the number of parameters.
virtual T | eval (FunctionArg x) const=0
| Evaluate the function object.
T & | operator[] (const uInt n)
| Manipulate the nth parameter (0-based) with no index check.
virtual T | operator() () const
| Evaluate this function object at xor at x, y.
Bool & | mask (const uInt n)
| Manipulate the mask associated with the nth parameter (e.g.
const FunctionParam< T > & | parameters () const
| Return the parameter interface.
const Vector< ArgType > & | argp () const
| Get arg_p and parset_p.
Bool | parsetp () const
void | lockParam ()
| Compiler cannot always find the correct 'const' version of parameter access.
void | unlockParam ()
ostream & | print (ostream &os) const
| Print the function (i.e.
virtual Function< typename FunctionTraits< T >::DiffType > * | cloneAD () const
virtual Function< typename FunctionTraits< T >::BaseType > * | cloneNonAD () const
Public Member Functions inherited from casacore::Functional< FunctionTraits< T >::ArgType, T >
virtual | ~Functional ()
| Destructor.
virtual T | operator() (const FunctionTraits< T >::ArgType &x) const=0
| Map a Domain x into a Range y value.
Public Member Functions inherited from casacore::Functional< Vector< FunctionTraits< T >::ArgType >, T >
virtual | ~Functional ()
| Destructor.
virtual T | operator() (const Vector< FunctionTraits< T >::ArgType > &x) const=0
| Map a Domain x into a Range y value.

## Additional Inherited Members

Public Types inherited from casacore::Function1D< T, U >
typedef const T * | FunctionArg
Public Types inherited from casacore::Function< T, T >
typedef FunctionTraits< T >::ArgType | ArgType
typedef const ArgType * | FunctionArg
Static Public Member Functions inherited from casacore::ChebyshevParam< T >
static void | derivativeCoeffs (Vector< T > &coeffs, const T &xmin=T(-1), const T &xmax=T(1))
| transform a set of Chebyshev polynomial coefficients into a set representing the series' derivative.
static void | chebyshevToPower (Vector< T > &coeffs)
| convert a set of Chebyshev polynomial coefficients to power series coefficients.
static void | powerToChebyshev (Vector< T > &coeffs)
| convert a set of power series coefficients to Chebyshev polynomial coefficients.
Protected Attributes inherited from casacore::ChebyshevParam< T >
T | def_p
| Default value if outside interval.
T | minx_p
| Lowest interval bound.
T | maxx_p
| Highest inetrval bound.
ChebyshevEnums::OutOfIntervalMode | mode_p
| Out-of-interval handling type.
Protected Attributes inherited from casacore::Function< T, T >
FunctionParam< T > | param_p
| The parameters and masks.
Vector< ArgType > | arg_p
| Aid for non-contiguous argument storage.
Bool | parset_p
| Indicate parameter written.
Bool | locked_p
| Indicate that parameters are expected to be locked from changing.
Static Protected Attributes inherited from casacore::ChebyshevParam< T >
static Vector< String > | modes_s

## Detailed Description

template<class T>
class casacore::Chebyshev< T >

A function class that defines a Chebyshev polynomial

### Intended use:

Public interface

### Review Status

Reviewed By:
  wbrouw
Date Reviewed:
  2001/11/12
Test programs:
  tChebyshev

### Prerequisite

- Function

### Etymology

This class is named after Chebyshev Type I polynomials

### Synopsis

This class allows one to form and evaluate a function as a Chebyshev series, a linear combination of so-called Chebyshev polynomials.

This class's implementation is split into two parts: the parent class ChebyshevParam<T>, which manages the function's parameters, and this class, which handles how the function is evaluated. Thus, be sure to also consult ChebyshevParam<T> for the full interface of this function.

### About Chebyshev Polynomials

Chebyshev polynomials are a special type of ultraspheric polynomials that are useful in such contexts as numerical analysis and circuit design. They form an orthogobnal set. A (type I) Chebyshev polynomial, T_n, is generated via the equation:

T_n(x) = cos n(arccos x)
casacore::cos
LatticeExprNode cos(const LatticeExprNode &expr)

Through clever use of trigometric identities, one can express T_n as a real polynomial expression of the form

n
T_n(x) = SUM C_i t^i
i=0

The low order polynomials look like this:

T_0 = 1
T_1 = x
T_2 = 2x^2 - 1
T_3 = 4x^3 - 3x
T_4 = 8x^4 - 8x^2 + 1
T_5 = 16x^5 - 20x^3 + 5x

Higher order polynomials satisfy the recurrance relation,

T_(n+1) = 2xT_(n) - T_(n-1).

A common use of Chebyshev polynomials is in approximating functions. In particular, any function that is approximated by a power series,

f(x) ~ SUM P_i x^i,

over the interval [-1, 1] can be approximated by a linear combination of Chebyshev polynomials:

f(x) ~ SUM C_i T_i(x),

where C_i is the set of so-called Chebyshev coefficients.

Approximating a function with Chebyshev polynomials has some important advantages. For one, if the function is well approximated by a converging power series, one can obtain an equally accurate estimate using fewer terms of the corresponding Chebyshev series. More important, though, is the property over the interval [-1, 1], each polynomial has a domain of [-1, 1]; thus, the series is nicely bounded. And because of this bounded property, approximations calculated from a Chebyshev series are less susceptible to machine rounding errors than the equivalent power series.

### Using the Chebyshev Function class

With a simple change of variable, it is possible to approximate a continuous function over any restricted interval using a Chebyshev series. This documention refers to this interval as the Chebyshev interval (set with the setInterval() function). The other important input parameters, of course, include the coefficients of the polynomials.

Like all Functions, the Chebyshev series is evaluated via the function operator, operator(). If the input value is within the range set by setInterval(), it is transformed to the range [-1, 1] via,

y = x - (min + max)/2) / ((max - min)/2)
casacore::max
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
casacore::min
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)

The series is then evaluated with the coefficients set either at construction or via setCoefficients(). The value that is returned when the input value is outside the Chebyshev interval depends on the out-of-interval mode (set via setOutOfIntervalMode()). The default mode is to return a default value which can be set via setDefault(). The supported modes are identified by the enumeration OutOfIntervalMode; see the documentation for ChebyshevParam for a detailed description of these modes. In practice, though, it is expected that this class will be configured for the interval of interest.

The derivative of a Chebyshev series with respect to the independent variable (i.e. the argument x) is easily calculated analytically and can be expressed as another Chebyshev series; this is what the derivative() function returns. However, the more general way to obtain derivatives is via the AutoDiff
templated type.

### Example

In this example, a 2nd order Chebyshev polynomial series is created.

// set coeffs to desired values
Vector<Double> coeffs(3, 1);
// configure the function
Chebyshev<Double> cheb;
cheb.setInterval(-0.8, 7.2);
cheb.setDefault(1.0);
cheb.setCoefficients(coeffs);
// evaluate the function as necessary
Double z = cheb(-0.5); // -0.5 is within range, z = 0.78625
z = cheb(4.2); // 4.2 is within range, z = 0.375
z = cheb(-3); // -3 is out of the interval, z = 1
casacore::ChebyshevParam::setCoefficients
void setCoefficients(const Vector< T > &coeffs)
set the Chebyshev coefficients.
casacore::ChebyshevParam::setDefault
void setDefault(const T &val)
set the default value of this function.
Definition ChebyshevParam.h:298
casacore::ChebyshevParam::setInterval
void setInterval(T xmin, T xmax)
set the Chebyshev interval for this function.
Definition ChebyshevParam.h:272
casacore::Chebyshev::Chebyshev
Chebyshev()
create a zero-th order Chebyshev polynomial with the first coefficient equal to zero.
Definition Chebyshev.h:240
casacore::Vector
Definition Vector.h:82
casacore::Double
double Double
Definition aipstype.h:53

The next example illustrates how to use the AutoDiff class to simultaneously calculate derivatives. Here, we replace the Double type with AutoDiff<Double>.

Chebyshev<AutoDiffA<Double> > cheb;
cheb.setDefault(AutoDiffA<Double>(1));
cheb.setInterval(AutoDiffA<Double>(-0.8), AutoDiffA<Double>(7.2));
// we'll track derivatives with respect to x and each of our
// coefficients; for a second-order series, this makes 4
// derivatives total. x will be the first variable; the
// coefficients will the 2nd-4th variables
cheb.setCoefficient(0, AutoDiffA<Double>(3.1, 4, 1)); // c0 = 3.1
cheb.setCoefficient(1, AutoDiffA<Double>(2.4, 4, 2)); // c1 = 2.4
cheb.setCoefficient(2, AutoDiffA<Double>(0.5, 4, 3)); // c2 = 0.5
// now evaluate the function
AutoDiffA<Double> x(1.2, 4, 0); // x = 1.2
AutoDiffA<Double> y = cheb(x); // y = 1.65
Double dydx = y.derivative(0); // dy/dx = 0.35
Double dydc1 = y.derivative(2); // dy/dc1 = -0.5
casacore::AutoDiffA
Definition AutoDiffA.h:116
casacore::AutoDiff::derivative
T & derivative(uInt which)
Returns a specific derivative.
Definition AutoDiff.h:324
casacore::ChebyshevParam::setCoefficient
void setCoefficient(const uInt which, const T &value)
set a particular Chebyshev coefficient.

### Motivation

This class was created to support systematic errors in the simulator tool.
It can be used by Jones matrix classes to vary gains in a predictable way, mimicing natural processes of the atmosphere or instrumental effects.

### Template Type Argument Requirements (T)

- T should have standard numerical operators. Current implementation only tested for real types (and their AutoDiffs).

### Thrown Exceptions

- Assertion in debug mode if attempt is made to address incorrect coefficients

### To Do

- It would be helpful to be able to convert to and from the Polynomial<T> type; this would be supported via a function, Polynomial<T> polynomial(), and constructor, Chebyshev(Polynomial<T>)

Definition at line 233 of file Chebyshev.h.

## Constructor & Destructor Documentation

## Chebyshev() [1/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( |  | ) |

inline

create a zero-th order Chebyshev polynomial with the first coefficient equal to zero.

The bounded domain is [T(-1), T(1)]. The OutOfDomainMode is CONSTANT, and the default value is T(0).

Definition at line 240 of file Chebyshev.h.

References casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl().

Referenced by Chebyshev(), clone(), derivative(), casacore::MarshallableChebyshev< T >::MarshallableChebyshev(), casacore::MarshallableChebyshev< T >::MarshallableChebyshev(), casacore::MarshallableChebyshev< T >::MarshallableChebyshev(), casacore::MarshallableChebyshev< T >::MarshallableChebyshev(), casacore::MarshallableChebyshev< T >::MarshallableChebyshev(), casacore::MarshallableChebyshev< T >::MarshallableChebyshev(), operator=(), and casacore::MarshallableChebyshev< T >::operator=().

## Chebyshev() [2/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( | const uInt | n | ) |

inline explicit

create an n-th order Chebyshev polynomial with the coefficients equal to zero.

The bounded domain is [T(-1), T(1)]. The OutOfDomainMode is CONSTANT, and the default value is T(0).

Definition at line 245 of file Chebyshev.h.

References casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl().

## Chebyshev() [3/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( | const T & | min,
|  | const T & | max,
|  | const typename ChebyshevEnums::OutOfIntervalMode | mode = ChebyshevEnums::CONSTANT,
|  | const T & | defval = T(0) )

inline

create a zero-th order Chebyshev polynomical with the first coefficient equal to one.

min is the minimum value of its Chebyshev interval, and max is the maximum value.
mode sets the behavior of the function outside the Chebyshev interval (see setOutOfIntervalMode() and OutOfIntervalMode enumeration definition for details).
defval is the value returned when the function is evaluated outside the Chebyshev interval and mode=CONSTANT.

Definition at line 256 of file Chebyshev.h.

References casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl(), casacore::ChebyshevEnums::CONSTANT, casacore::max(), and casacore::min().

## Chebyshev() [4/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( | const Vector< T > & | coeffs,
|  | const T & | min,
|  | const T & | max,
|  | const typename ChebyshevEnums::OutOfIntervalMode | mode = ChebyshevEnums::CONSTANT,
|  | const T & | defval = T(0) )

inline

create a fully specified Chebyshev polynomial.

coeffs holds the coefficients of the Chebyshev polynomial (see setCoefficients() for details). min is the minimum value of its canonical range, and max is the maximum value.
mode sets the behavior of the function outside the Chebyshev interval (see setOutOfIntervalMode() and OutOfIntervalMode enumeration definition for details).
defval is the value returned when the function is evaluated outside the canonical range and mode=CONSTANT.

Definition at line 272 of file Chebyshev.h.

References casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl(), casacore::ChebyshevEnums::CONSTANT, casacore::max(), and casacore::min().

## Chebyshev() [5/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( | uInt | order,
|  | const RecordInterface & | mode )

inline

create a fully specified Chebyshev polynomial.

config is a record that contains the non-coefficient data that configures this class. The fields recognized by this class are those documented for the ChebyshevPara::setMode()
function.

Definition at line 285 of file Chebyshev.h.

References casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl(), casacore::ChebyshevParam< T >::order(), and casacore::RecordInterface().

## Chebyshev() [6/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( | const Vector< T > & | coeffs,
|  | const RecordInterface & | mode )

inline

Definition at line 287 of file Chebyshev.h.

References casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl(), and casacore::RecordInterface().

## Chebyshev() [7/7]

template<class T>

casacore::Chebyshev< T >::Chebyshev | ( | const Chebyshev< T > & | other | ) |

inline

create a deep copy of another Chebyshev polynomial

Definition at line 293 of file Chebyshev.h.

References Chebyshev(), and casacore::ChebyshevParamModeImpl< T >::ChebyshevParamModeImpl().

## ~Chebyshev()

template<class T>

virtual casacore::Chebyshev< T >::~Chebyshev | ( |  | ) |

inline virtual

Destructor.

Definition at line 301 of file Chebyshev.h.

## Member Function Documentation

## clone()

template<class T>

virtual Function< T > * casacore::Chebyshev< T >::clone | ( |  | ) | const

inline virtual

Create a new copy of this object.

The caller is responsible for deleting the pointer.

Implements casacore::Function< T, T >.

Reimplemented in casacore::MarshallableChebyshev< T >.

Definition at line 315 of file Chebyshev.h.

References Chebyshev().

## derivative()

template<class T>

Chebyshev< T > casacore::Chebyshev< T >::derivative | ( |  | ) | const

Return the Chebyshev polynomial which is the derivative of this one (with respect to the argument x).

References Chebyshev().

## eval()

template<class T>

virtual T casacore::Chebyshev< T >::eval | ( | const typename FunctionTraits< T >::ArgType * | x | ) | const

virtual

Evaluate the Chebyshev at x.

## operator=()

template<class T>

Chebyshev< T > & casacore::Chebyshev< T >::operator= | ( | const Chebyshev< T > & | other | ) |

inline

make this instance a (deep) copy of another Chebyshev polynomial

Definition at line 297 of file Chebyshev.h.

References Chebyshev(), and casacore::ChebyshevParam< T >::operator=().

Referenced by casacore::MarshallableChebyshev< T >::operator=(), and casacore::MarshallableChebyshev< T >::operator=().

The documentation for this class was generated from the following file:

- scimath/Functionals/Chebyshev.h