CompoundFunction.h

Classes

CompoundFunction -- Sum of a collection of Functions which behaves as one Function object. (full description)
CompoundFunction_PS -- Partial AutoDiff specialization of CompoundFunction (full description)

template <class T> class CompoundFunction : public CompoundParam<T>

Interface

Public Members
CompoundFunction() : CompoundParam<T>()
CompoundFunction(const CompoundFunction<T> &other) : other<T>(other)
CompoundFunction(const CompoundFunction<T> &other, Bool) : other<T>(other, True)
template <class W> CompoundFunction(const CompoundFunction<W> &other) : CompoundParam<T>(other)
template <class W> CompoundFunction(const CompoundFunction<W> &other, Bool) : CompoundParam<T>(other, True)
CompoundFunction<T> &operator=(const CompoundFunction<T> &other)
virtual ~CompoundFunction()
virtual T eval(typename Function<T>::FunctionArg x) const
CompoundFunction<T> &consolidate()
virtual Function<T> *clone() const
virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const
virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const
Private Members
void fromParam_p() const
void toParam_p()

Description

Prerequisite

Synopsis

This class takes an arbitrary number of Function objects, and generates a new, single function object. The parameters of the compound object are the union of all the parameters in the input objects.

When CompoundFunction is evaluated, the result is the sum of all the individual function values.

Member functions are added with the addFunction() method.

In general the interaction with the function parameters should be through the overall function parameters (i.e. through the parameters of the CompoundFunction). If for any reason you want to set the parameters of an individual function (see e.g. the example in the Fit2D), call consolidate() before and after the actual setting.

Tip Check CombiFunction class for a simple linear combination of function objects

Example

Suppose for some reason we wanted the sum of x^2 plus a gaussian. We could form it as follows:
    Polynomial<Float> x2(2);
    x[2] = 1.0; 					 // x^2
    Gaussian1D<Float> gauss(1.0, 0.0, 1.0);          // e^{-x^2}
    CompoundParam<Float> sum;                        // sum == 0.0
    sum.addFunction(x2);                               // sum == x^2
    sum.addFunction(gauss);                            // sum == x^2+e^{-x^2}
    sum(2.0);                                          // == 4 + e^-4
    CompoundParam[0] = 2.0;                          // sum ==2x^2+e^{-x^2}
    sum(2.0);                                          // == 8 + e^-4

Template Type Argument Requirements (T)

Thrown Exceptions

Motivation

This class was created to allow a non-linear least squares fitter to fit a (potentially) arbitrary number of functions (typically Gaussians).

To Do

Member Description

CompoundFunction() : CompoundParam<T>()

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

CompoundFunction(const CompoundFunction<T> &other) : other<T>(other)
CompoundFunction(const CompoundFunction<T> &other, Bool) : other<T>(other, True)
template <class W> CompoundFunction(const CompoundFunction<W> &other) : CompoundParam<T>(other)
template <class W> CompoundFunction(const CompoundFunction<W> &other, Bool) : CompoundParam<T>(other, True)

Make this object a (deep) copy of other. If parameters have been set without an intervening calculation, a consolidate() could be necessary on other first.

CompoundFunction<T> &operator=(const CompoundFunction<T> &other)

Make this object a (deep) copy of other.

virtual ~CompoundFunction()

Destructor

virtual T eval(typename Function<T>::FunctionArg x) const

Evaluate the function at x.

CompoundFunction<T> &consolidate()

Consolidate the parameter settings. This could be necessary if parameters have been set, and a copy constructor called. This is necessary before and after the setting of local parameters; i.e. the parameters of the individual functions.

virtual Function<T> *clone() const
virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const
virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const

Return a copy of this object from the heap. The caller is responsible for deleting the pointer.

void fromParam_p() const

Copy the local parameters from general block

void toParam_p()

Make the general block from local parameters

template <class T> class CompoundFunction_PS<AutoDiff<T> > :public CompoundParam<AutoDiff<T> >

Interface

Public Members
CompoundFunction_PS() : CompoundParam<AutoDiff<T> >()
CompoundFunction_PS(const CompoundFunction_PS<AutoDiff<T> > &other) : other<AutoDiff<T> >(other)
template <class W> CompoundFunction_PS(const CompoundFunction_PS<W> &other) : CompoundParam<other<T> >(other)
CompoundFunction_PS<AutoDiff<T> > & operator=(const CompoundFunction_PS<AutoDiff<T> > &other)
virtual ~CompoundFunction_PS()
virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const
uInt addFunction(const Function<AutoDiff<T> > &newFunction)
CompoundFunction_PS<AutoDiff<T> > &consolidate()
virtual Function<AutoDiff<T> > *clone() const
virtual Function<typename FunctionTraits<Traits<T> >::DiffType> *cloneAD() const
virtual Function<typename FunctionTraits<Traits<T> >::BaseType> *cloneNonAD() const
Private Members
void fromParam_p() const
void toParam_p()

Description

Synopsis

Warning The name CompoundFunction_PS is only for cxx2html documentation problems. Use CompoundFunction in your code.

Member Description

CompoundFunction_PS() : CompoundParam<AutoDiff<T> >()

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

CompoundFunction_PS(const CompoundFunction_PS<AutoDiff<T> > &other) : other<AutoDiff<T> >(other)
template <class W> CompoundFunction_PS(const CompoundFunction_PS<W> &other) : CompoundParam<other<T> >(other)

Make this object a (deep) copy of other. If parameters have been set without an intervening calculation, a consolidate() could be necessary on other first.

CompoundFunction_PS<AutoDiff<T> > & operator=(const CompoundFunction_PS<AutoDiff<T> > &other)

Make this object a (deep) copy of other.

virtual ~CompoundFunction_PS()

Destructor

virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const

Evaluate the function and its derivatives at x wrt to the coefficients.

uInt addFunction(const Function<AutoDiff<T> > &newFunction)

Add a function to the sum. All functions must have the same ndim() as the first one. Returns the (zero relative) number of the function just added.

CompoundFunction_PS<AutoDiff<T> > &consolidate()

Consolidate the parameter settings. This could be necessary if parameters have been set, and a copy constructor called. This is necessary before and after the setting of local parameters; i.e. the parameters of the individual functions.

virtual Function<AutoDiff<T> > *clone() const
virtual Function<typename FunctionTraits<Traits<T> >::DiffType> *cloneAD() const
virtual Function<typename FunctionTraits<Traits<T> >::BaseType> *cloneNonAD() const

Return a copy of this object from the heap. The caller is responsible for deleting the pointer.

void fromParam_p() const

Copy the local parameters to/from general block

void toParam_p()

Make the general block from local parameters