casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Modules | Classes

A module that represents various function-like classes. More...

Modules

 Functionals_module_internal_classes
 Internal Functionals_module classes and functions.
 

Classes

class  casacore::FunctionFactory< T >
 a class for creating Function objects from Records More...
 
class  casacore::ArraySampledFunctional< T >
 Index into an array using the longest axis. More...
 
class  casacore::Chebyshev< T >
 A function class that defines a Chebyshev polynomial. More...
 
class  casacore::ChebyshevEnums
 Define enums for Chebyshev classes. More...
 
class  casacore::ChebyshevParamModeImpl< T >
 A ChebyshevParam with the get/setMode implementation. More...
 
class  casacore::ChebyshevParamModeImpl_PS< AutoDiff< T > >
 Partial specialization of ChebyshevParamModeImpl for AutoDiff More...
 
class  casacore::ChebyshevParamModeImpl_PSA< AutoDiffA< T > >
 Partial specialization of ChebyshevParamModeImpl for AutoDiff More...
 
class  casacore::CombiFunction< T >
 Form a linear combination of function objects. More...
 
class  casacore::CompiledFunction< T >
 Form a linear combination of function objects. More...
 
class  casacore::CompoundFunction< T >
 Sum of a collection of Functions which behaves as one Function object. More...
 
class  casacore::ConstantND< T >
 A constant function. More...
 
class  casacore::DiracDFunction< T >
 A one dimensional Dirac delta function. More...
 
class  casacore::EclecticFunctionFactory< T >
 
class  casacore::EvenPolynomial< T >
 A one dimensional odd polynomial class. More...
 
class  casacore::EvenPolynomialParam< T >
 Parameter handling for even polynomials. More...
 
struct  casacore::FuncExprData_global_functions_output
 Output function. More...
 
class  casacore::FuncExpression
 An expression executable as function. More...
 
struct  casacore::FuncExpression_global_functions_output
 Output function. More...
 
struct  casacore::FuncExpression_global_functions_execute
 Execute function. More...
 
class  casacore::Function< T, U >
 Numerical functional interface class. More...
 
struct  casacore::Function_global_functions_Output
 Global functions. More...
 
class  casacore::Function1D< T, U >
 Numerical functional interface class for 1 dimension. More...
 
class  casacore::FunctionHolder< T >
 A holder for Functions to enable record conversions. More...
 
class  casacore::FunctionMarshallable
 a class for serializing/reconstituting Function objects to/from Records More...
 
class  casacore::FunctionOrder< T >
 Container of function description details. More...
 
struct  casacore::FunctionOrder_global_functions_Output
 Global functions. More...
 
class  casacore::FunctionParam< T >
 Container of function parameters with masking flags. More...
 
struct  casacore::FunctionParam_global_functions_Output
 Global functions. More...
 
class  casacore::FunctionTraits< T >
 Function data types for parameters and arguments. More...
 
class  casacore::FunctionTraits_P< AutoDiff< T > >
 FunctionTraits specialization for AutoDiff. More...
 
class  casacore::FunctionTraits_PA< AutoDiffA< T > >
 FunctionTraits specialization for AutoDiffA. More...
 
class  casacore::FunctionTraits_PX< AutoDiffX< T > >
 FunctionTraits specialization for AutoDiffX. More...
 
class  casacore::FunctionWrapper< T >
 Construct nD function objects from C++ functions. More...
 
class  casacore::Gaussian1D< T >
 A one dimensional Gaussian class. More...
 
class  casacore::Gaussian2D< T >
 A two dimensional Gaussian class. More...
 
class  casacore::Gaussian3D< T >
 A three dimensional Gaussian class. More...
 
class  casacore::GaussianND< T >
 A Multi-dimensional Gaussian functional. More...
 
class  casacore::GNoiseFunction< T >
 A one dimensional normal distribution. More...
 
class  casacore::HyperPlane< T >
 A hyper plane function. More...
 
class  casacore::Interpolate1D< Domain, Range >
 Interpolate in one dimension. More...
 
class  casacore::KaiserBFunction< T >
 A one dimensional Kaiser-Bessel function. More...
 
class  casacore::Lorentzian1D< T >
 A one dimensional Lorentzian class. More...
 
class  casacore::MarshallableChebyshev< T >
 A Chebyshev function class that supports serialization. More...
 
class  casacore::MarshButterworthBandpass< T >
 A Butterworth function class that supports serialization. More...
 
class  casacore::OddPolynomial< T >
 A one dimensional odd polynomial class. More...
 
class  casacore::OddPolynomialParam< T >
 Parameter handling for odd polynomials. More...
 
class  casacore::PoissonFunction< T >
 A one dimensional Poisson function. More...
 
class  casacore::Polynomial< T >
 A one dimensional polynomial class. More...
 
class  casacore::PolynomialParam< T >
 Parameter handling for one-dimensional polynomials. More...
 
class  casacore::PowerLogarithmicPolynomial< T >
 A one dimensional power logarithmic polynomial class of form y = c_0 * x**(c_1 + c_2*ln(x) + c_3*ln(x)**2 +... c_n*ln(x)**(n-1)) More...
 
class  casacore::PowerLogarithmicPolynomialParam< T >
 Parameter handling for one-dimensional power logarithmic polynomials. More...
 
class  casacore::SampledFunctional< Range >
 A base class for indexing into arbitrary data types. More...
 
class  casacore::ScalarSampledFunctional< T >
 A unified interface for indexing into Vectors or Blocks. More...
 
class  casacore::SerialHelper
 
class  casacore::SimButterworthBandpass< T >
 a class for evaluating a Butterworth filter transfer function. More...
 
class  casacore::SincFunction< T >
 A one dimensional sin(x)/x. More...
 
class  casacore::Sinusoid1D< T >
 A one dimensional Sinusoid class. More...
 
class  casacore::SpecificFunctionFactory< T, F >
 
class  casacore::SPolynomial< T >
 A one dimensional scaled polynomial class. More...
 
class  casacore::SPolynomialParam< T >
 Parameter handling for scaled 1-D polynomials. More...
 
class  casacore::UnaryFunction< T >
 A one dimensional unary function. More...
 
class  casacore::WrapperData_TT< T, T, T, True, True >
 Specialization for calls with argument and parameter. More...
 
class  casacore::WrapperData_VT< T, Vector< T >, T, True, True >
 Specialization for calls with argument and parameter. More...
 
class  casacore::WrapperData_TV< T, T, Vector< T >, True, True >
 Specialization for calls with argument and parameters. More...
 
class  casacore::WrapperData_VV< T, Vector< T >, Vector< T >, True, True >
 Specialization for calls with argument and parameters. More...
 
class  casacore::WrapperData_FT< T, T, T, False, True >
 Specialization for calls with no arguments and parameter. More...
 
class  casacore::WrapperData_FV< T, T, Vector< T >, False, True >
 Specialization for calls with no arguments and parameters. More...
 
class  casacore::WrapperData_TF< T, T, T, True, False >
 Specialization for calls with argument and no parameters. More...
 
class  casacore::WrapperData_VF< T, Vector< T >, T, True, False >
 Specialization for calls with argument and no parameters. More...
 
class  casacore::WrapperData_FF< T, T, T, False, False >
 Specialization for calls with no arguments and no parameters. More...
 

Detailed Description

A module that represents various function-like classes.

See below for an overview of the classes in this module.

Review Status

Reviewed By:
tcornwel
Date Reviewed:
1996/02/13

Etymology

The term Functional was chosen to roughly follow the usage in Barton and Nackman's Scientific and Engineering C++. Functional classes map a Domain object into a Range object, rather like a mathematical function. They use operator(), so they look much like single argument C++ functions.

Synopsis

Functionals and their derived classes map an input Domain object into an output Range object using the operator(). Often the input and output types are numeric, but it can be of any type.

class Offspring : public Functional<List<Parents>, List<Children> > {
public:
List<Children> operator()(List<Parents>);
};

would be a legal Functional.

The Functions and their derived classes map, again using the operator(), numeric value(s) into a numeric value. Since they are numeric, the Domain and Range base type can be of type AutoDiff<T> (where T is numeric base type) or one of its derivations, in which case the value and its derivatives will be calculated.


Warning: In the current version the Domain and Range are the same for Functions

The basic classes are:

Functional<Domain, Range>

A base class that maps a Domain object into a Range object using the Range operator(const Domain &). All information necessary to convert the Domain into a Range will be available in the class or in the input information. No variable class state (parameters) are available.

FunctionParam<T>

A helper base class that acts as a container for parameters (state) used in Function classes. The class contains a list of parameters, and a list of flags associated with the parameters. Methods to set and obtain the parameters (using operator[]) and their flags (using methods mask()) are available. The flags can e.g. be used to indicate to Fitting routines if a certain parameter has to be updated ('fitted') or not.
Tip: The FunctionParam class does not assume anything about the uses of the class, but leaves that to the final users; This means that a lot of copying between intermediate and final users is not necessary (like between a Gaussian fitter with fixed parameters and the Fitting routines: the Gaussian fitter just sets a flag to False, and let the Fitting worry about what to do internally);

Function<T>

Base class for function objects with zero or more parameters (i.e. Functionals with state). All parameters should be of the same type T as the Function<T>. Function objects are specifically geared towards use in the Fitting classes, but can be used anywhere where the value (and/or derivatives) of functions are needed.

The Function<T> class is derived from Functional and contains a FunctionParam<T> object. The parameters act as state for the function (e.g. a width for a Gaussian). A function object is called using the T operator(const T&) (ndim=1), or the T operator(const Vector<T>&) (all values of ndim), or T operator(const T&, const T&) (for ndim=2 only). If the template argument is AutoDiff<T>, the parameters and the returned value will be AutoDiff<T>; the arguments of the operator() will be of type T. The returned value of the function will be the function value at x (and the derivatives w.r.t. the non-masked parameters) Using AutoDiffA<T> the derivatives can be calculated w.r.t. parameters and/or arguments, see AutoDiff and FunctionTraits for details.


Tip: A Function1D is provided for 1-dimensional function objects

Actual functional classes:

e.g. Gaussian1D<T>

An actual function object will be derived from Function<T>. The minimum functionality of a Function object will be support for the operator() methods (through a single, hidden, eval() method); for the manipulation of the associated parameters (using operator[index] and mask(index)) and some administrative aids (ndim(), nparameters() and the like.

In most cases it is advantageous to have a special parameter handling class (e.g. Gaussian1DParam), to separate the (template independent) parameter handling from the possible specialization of the eval() method, and to more easily incorporate special parameter handling (e.g. using flux rather than amplitude of a Gaussian). All of this is transparent to the end-user.

Combinatory Function objects are provided to easily combine and create function objects:

CompoundFunction
creates a new, compound, function object from one or more other function objects (including compounds...). The new function will have the sum of the parameters of the input functions as the new parameters (i.e. the compound function created from a 1-dimensional Gaussian (with 3 parameters) and a third-order polynomial (with 4 parameters) will have 7 parameters).
CombiFunction
creates a (linear) combination of a number of input functions. The number of parameters of the newly created function will be equal to the number of input functions (i.e. the combi function created from a 1-dimensional Gaussian (with 3 parameters) and a third-order polynomial (with 4 parameters) will have 2 parameters). The function will be param0*gauss(x) + param1*poly(x)
FunctionWrapper

will take a global function (or by the use of the STL function adapters mem_fun* also member functions) of any dimension, and with any number of parameters. The function is assumed to be called as f(x, p), and is wrapped like FunctionWrapper(&func, param&, ndim) (see example).

Example

A function to find a bracketed root by bisection could be written as follows:

template <class Domain, class Range>
Domain findRoot(const Functional<Domain,Range> &func, Domain left,
Domain right, Domain tol) {
Range fr = func(right);
Range fl = func(left);
Range sign = fr > 0 ? 1 : -1 ;
AlwaysAssertExit(fl*fr < 0.0 && right > left);
while (right - left > tol) {
Domain mid = (left + right) / 2;
Range fmid = func(mid);
if (sign*fmid > 0.0) right = mid;
else left = mid;
};
return (left + right)/2;
}

Since Function1D is derived from Functional, the above function will also work with classes derived from Function1D. To behave sensibly, the Domain and Range types should be real, i.e., Float or Double.

To calculate the value of a polynomial

2 + 4x<sup>2</sup> + 6x<sup>4</sup>

at x=5.1:

Polynomial<Double> pol(4);
pol[0] = 2; pol[2] = 4; pol[4] = 6;
cout << "Polynomial value at 5.1: " << pol(5.1) << endl;

Create a simple function (1-dimensional) with 2 parameters (A and B):

Double myf(const Double x, const Vector<Double> p) {
return p[0]*sin(p[1]*x); }

make it into a function object for initial parameters 2 and pi:

Vector<Double> p(2);
p[0] = 2; p[1] = C::pi;
FunctionWrapper<Double> f0(myf, p, 2);

Make the first parameter 3:

f0[0] = 3;

(for the global function you have to change p[0]). Calculate the value of the function:

cout << "The value " << f0(3) << " should be 1.5 times the value " <<
myf(3) << endl;

A function object could be created as:

template<class T> class objf : public Function<T> {
public:
objf() : Function<T>(2) {}; // 2 parameters
objf(const objf<T> &other) : Function<T>(other) {};
virtual ~objf() {};
// The actual method called for the evaluation operator():
virtual T eval(typename Function<T>::FunctionArg x) const {
return param_p[0] * sin(param_p[1] * x[0]); };
// Return a copy of function (used for combination e.g.)
virtual Function<T> *clone() const {
return new objf<T>(*this); };
};

Which can be called as:

objf<Double> f1;
f1[0] = 2; f1[1] = C::pi;
cout << "The value " << myf(3) << " should be equal to the value " <<
f1(3) << endl;

Motivation

The immediate motivations for this module were:

  1. To represent functions which are used in linear and non-linear least squares fitting

To Do