casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions
casa::CompiledFunction< T > Class Template Reference

Form a linear combination of function objects. More...

#include <CompiledFunction.h>

Inheritance diagram for casa::CompiledFunction< T >:
casa::CompiledParam< T > casa::Function< T > casa::Functional< FunctionTraits< T >::ArgType, T > casa::Functional< Vector< FunctionTraits< T >::ArgType >, T >

List of all members.

Public Member Functions

 CompiledFunction ()
 The default constructor -- no functions, no parameters, nothing, the function operator returns a 0.
 CompiledFunction (const CompiledFunction< T > &other)
 Make this object a (deep) copy of other.
template<class W >
 CompiledFunction (const CompiledFunction< W > &other)
CompiledFunction< T > & operator= (const CompiledFunction< T > &other)
 Make this object a (deep) copy of other.
virtual ~CompiledFunction ()
 Destructor.
virtual T eval (typename Function< T >::FunctionArg x) const
 Evaluate the function at x.
virtual Function< T > * clone () const
 Return a copy of this object from the heap.
virtual Function< typename
FunctionTraits< T >::DiffType > * 
cloneAD () const
virtual Function< typename
FunctionTraits< T >::BaseType > * 
cloneNonAD () const

Detailed Description

template<class T>
class casa::CompiledFunction< T >

Form a linear combination of function objects.

Intended use:

Public interface

Review Status

Test programs:
tFuncExpression

Prerequisite

Synopsis

Given a string describing an expression (see FuncExpression class for details of the expression), the CompiledFunctionclass wraps this expression as a Function (see Function class) which can be used in all places where functions can be used (e.g. see Fitting ).

The CompiledParam class takes care of the parameter interface.

Example

In the following example a Gaussian profile with three parameters (height, center and halfwidth) is specified and its value and derivatives with respect to the parameters are calculated at x=[1.9,2,2.1].

    // the Gaussian
    CompiledFunction<Double> prof;
    prof.setFunction("p0*exp(-((x-p1)/p2)^2)");
    prof[0] = 2;                                // the height
    prof[1] = 1.5;                      // the center
    prof[2] = 1;                                // the width
    Vector<Double> x(3);
    x[0] = 1.9; x[1] = 2.0; x[2] = 2.1;
    for (uInt i=0; i<3; ++i) {
      cout << "Gaussian at x=" << x[i] << ": " << prof(x[i]) << endl;
    }
    // Calculate automatic derivatives of same function:
    CompiledFunction<AutoDiff<Double> > profad;
    profad.setFunction("p0*exp(-((x-p1)/p2)^2)");
    // Set the parameters (note the specification of the number of
    // derivatives and which derivative the parameter is)
    profad[0] = AutoDiff<Double>(2,  3,0);      // the height
    profad[1] = AutoDiff<Double>(1.5,3,1);      // the center
    profad[2] = AutoDiff<Double>(1,  3,2);              // the width
    for (uInt i=0; i<3; ++i) {
      cout << "Gaussian at x=" << x[i] << ": " << profad(x[i]) << endl;
    }
    cout << "Value (x=2): " << profad(x[1]).value() << endl;
    cout << "Derivatives: " << profad(x[1]).derivatives() << endl;
    cout << "Derivative1: " << profad(x[1]).derivatives()[1] << endl;

will produce the output:

        Gaussian at x=1.9: 1.70429
        Gaussian at x=2: 1.5576
        Gaussian at x=2.1: 1.39535
        Gaussian at x=1.9: (1.70429, [0.852144, 1.36343, 0.545372])
        Gaussian at x=2: (1.5576, [0.778801, 1.5576, 0.778801])
        Gaussian at x=2.1: (1.39535, [0.697676, 1.67442, 1.00465])
        Value (x=2): 1.5576
        Derivatives: [0.778801, 1.5576, 0.778801]
        Derivative1: 1.5576

Template Type Argument Requirements (T)

Motivation

This class was created to allow specialization of the function evaluation in a simple way.

To Do

Definition at line 131 of file CompiledFunction.h.


Constructor & Destructor Documentation

template<class T>
casa::CompiledFunction< T >::CompiledFunction ( ) [inline]

The default constructor -- no functions, no parameters, nothing, the function operator returns a 0.

Definition at line 136 of file CompiledFunction.h.

template<class T>
casa::CompiledFunction< T >::CompiledFunction ( const CompiledFunction< T > &  other) [inline]

Make this object a (deep) copy of other.

Definition at line 139 of file CompiledFunction.h.

template<class T>
template<class W >
casa::CompiledFunction< T >::CompiledFunction ( const CompiledFunction< W > &  other) [inline]

Definition at line 142 of file CompiledFunction.h.

template<class T>
virtual casa::CompiledFunction< T >::~CompiledFunction ( ) [inline, virtual]

Destructor.

Definition at line 150 of file CompiledFunction.h.


Member Function Documentation

template<class T>
virtual Function<T>* casa::CompiledFunction< T >::clone ( ) const [inline, virtual]

Return a copy of this object from the heap.

The caller is responsible for deleting the pointer.

Implements casa::Function< T >.

Definition at line 160 of file CompiledFunction.h.

template<class T>
virtual Function<typename FunctionTraits<T>::DiffType>* casa::CompiledFunction< T >::cloneAD ( ) const [inline, virtual]

Reimplemented from casa::Function< T >.

Definition at line 162 of file CompiledFunction.h.

template<class T>
virtual Function<typename FunctionTraits<T>::BaseType>* casa::CompiledFunction< T >::cloneNonAD ( ) const [inline, virtual]

Reimplemented from casa::Function< T >.

Definition at line 164 of file CompiledFunction.h.

template<class T>
virtual T casa::CompiledFunction< T >::eval ( typename Function< T >::FunctionArg  x) const [virtual]

Evaluate the function at x.

template<class T>
CompiledFunction<T>& casa::CompiledFunction< T >::operator= ( const CompiledFunction< T > &  other) [inline]

Make this object a (deep) copy of other.

Definition at line 146 of file CompiledFunction.h.


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