casacore
Modules | Classes

More...

Modules

 Functionals_module_internal_classes
 Internal Functionals_module classes and functions.
 

Classes

class  casacore::FunctionFactory< T >
  More...
 
class  casacore::ArraySampledFunctional< T >
  More...
 
class  casacore::Chebyshev< T >
  More...
 
class  casacore::ChebyshevEnums
  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 >
  More...
 
class  casacore::CompiledFunction< T >
  More...
 
class  casacore::CompoundFunction< T >
  More...
 
class  casacore::ConstantND< T >
  More...
 
class  casacore::DiracDFunction< T >
  More...
 
class  casacore::EclecticFunctionFactory< T >
  More...
 
class  casacore::EvenPolynomial< T >
  More...
 
class  casacore::EvenPolynomialParam< T >
  More...
 
struct  casacore::FuncExprData_global_functions_output
 Output function
More...
 
class  casacore::FuncExpression
  More...
 
struct  casacore::FuncExpression_global_functions_output
 Output function
More...
 
struct  casacore::FuncExpression_global_functions_execute
 Execute function
More...
 
class  casacore::Function< T, U >
  More...
 
struct  casacore::Function_global_functions_Output
 Global functions
More...
 
class  casacore::Function1D< T, U >
  More...
 
class  casacore::FunctionHolder< T >
  More...
 
class  casacore::FunctionMarshallable
  More...
 
class  casacore::FunctionOrder< T >
  More...
 
struct  casacore::FunctionOrder_global_functions_Output
 Global functions
More...
 
class  casacore::FunctionParam< T >
  More...
 
struct  casacore::FunctionParam_global_functions_Output
 Global functions
More...
 
class  casacore::FunctionTraits< T >
  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 >
  More...
 
class  casacore::Gaussian1D< T >
  More...
 
class  casacore::Gaussian2D< T >
  More...
 
class  casacore::Gaussian3D< T >
  More...
 
class  casacore::GaussianND< T >
  More...
 
class  casacore::GNoiseFunction< T >
  More...
 
class  casacore::HyperPlane< T >
  More...
 
class  casacore::Interpolate1D< Domain, Range >
  More...
 
class  casacore::KaiserBFunction< T >
  More...
 
class  casacore::Lorentzian1D< T >
  More...
 
class  casacore::MarshallableChebyshev< T >
  More...
 
class  casacore::MarshButterworthBandpass< T >
  More...
 
class  casacore::OddPolynomial< T >
  More...
 
class  casacore::OddPolynomialParam< T >
  More...
 
class  casacore::PoissonFunction< T >
  More...
 
class  casacore::Polynomial< T >
  More...
 
class  casacore::PolynomialParam< T >
  More...
 
class  casacore::PowerLogarithmicPolynomial< T >
  More...
 
class  casacore::PowerLogarithmicPolynomialParam< T >
  More...
 
class  casacore::SampledFunctional< Range >
  More...
 
class  casacore::ScalarSampledFunctional< T >
  More...
 
class  casacore::SerialHelper
  More...
 
class  casacore::SimButterworthBandpass< T >
  More...
 
class  casacore::SincFunction< T >
  More...
 
class  casacore::Sinusoid1D< T >
  More...
 
class  casacore::SpecificFunctionFactory< T, F >
  More...
 
class  casacore::SPolynomial< T >
  More...
 
class  casacore::SPolynomialParam< T >
  More...
 
class  casacore::UnaryFunction< T >
  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;
}
#define AlwaysAssertExit(expr)
Definition: Assert.h:159
LatticeExprNode sign(const LatticeExprNode &expr)

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); }
LatticeExprNode sin(const LatticeExprNode &expr)
Numerical 1-argument functions.
double Double
Definition: aipstype.h:55

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);
const Double pi
Pi and functions thereof:

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); };
};
const ArgType * FunctionArg
Definition: Function.h:207

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