Functionals
[scimath package (libscimath)]


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


Modules

 Functionals_internal_classes
 Internal Functionals classes and functions.

Classes

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


Generated on Tue Aug 26 22:25:17 2008 for NRAOCASA by  doxygen 1.5.1