casacore
Public Member Functions | Private Member Functions | List of all members
casacore::CompoundFunction< T > Class Template Reference

More...

#include <CompoundFunction.h>

Public Member Functions

 CompoundFunction ()
 The default constructor – no functions, no parameters, nothing, the function operator returns a 0. More...
 
 CompoundFunction (const CompoundFunction< T > &other)
 Make this object a (deep) copy of other. More...
 
 CompoundFunction (const CompoundFunction< T > &other, Bool)
 
template<class W >
 CompoundFunction (const CompoundFunction< W > &other)
 
template<class W >
 CompoundFunction (const CompoundFunction< W > &other, Bool)
 
CompoundFunction< T > & operator= (const CompoundFunction< T > &other)
 Make this object a (deep) copy of other. More...
 
virtual ~CompoundFunction ()
 Destructor. More...
 
virtual T eval (typename Function< T >::FunctionArg x) const
 Evaluate the function at x. More...
 
CompoundFunction< T > & consolidate ()
 Consolidate the parameter settings. More...
 
virtual Function< T > * clone () const
 Return a copy of this object from the heap. More...
 
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD () const
 
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD () const
 
- Public Member Functions inherited from casacore::CompoundParam< T >
 CompoundParam ()
 The default constructor – no functions, no parameters, nothing, the function operator returns a 0. More...
 
 CompoundParam (const CompoundParam< T > &other)
 Make this object a (deep) copy of other. More...
 
 CompoundParam (const CompoundParam< T > &other, Bool)
 
template<class W >
 CompoundParam (const CompoundParam< W > &other)
 
template<class W >
 CompoundParam (const CompoundParam< W > &other, Bool)
 
CompoundParam< T > & operator= (const CompoundParam< T > &other)
 
virtual ~CompoundParam ()
 
virtual const Stringname () const
 Give name of function. More...
 
uInt addFunction (const Function< T > &newFunction)
 Add a function to the sum. More...
 
uInt nFunctions () const
 Return the number of functions in the sum. More...
 
const Function< T > & function (uInt which) const
 Return a reference to a specific Function. More...
 
uInt parameterOffset (uInt which) const
 Get the offset in function parameterlist for function which. More...
 
uInt parameterFunction (uInt which) const
 Get the function number belonging to parameter list element which. More...
 
uInt parameterLocation (uInt which) const
 Return locpar. More...
 
virtual uInt ndim () const
 Returns the dimension of functions in the linear combination. More...
 
- Public Member Functions inherited from casacore::Function< T, U >
 Function ()
 Constructors. More...
 
 Function (const uInt n)
 
 Function (const Vector< T > &in)
 
 Function (const FunctionParam< T > &other)
 
template<class W , class X >
 Function (const Function< W, X > &other)
 
virtual ~Function ()
 Destructor. More...
 
uInt nparameters () const
 Returns the number of parameters. More...
 
virtual U eval (FunctionArg x) const =0
 Evaluate the function object. More...
 
T & operator[] (const uInt n)
 Manipulate the nth parameter (0-based) with no index check. More...
 
const T & operator[] (const uInt n) const
 
virtual U operator() () const
 Evaluate this function object at xor at x, y. More...
 
virtual U operator() (const ArgType &x) const
 
virtual U operator() (const Vector< ArgType > &x) const
 
virtual U operator() (FunctionArg x) const
 
virtual U operator() (const ArgType &x, const ArgType &y) const
 
virtual U operator() (const ArgType &x, const ArgType &y, const ArgType &z) const
 
Boolmask (const uInt n)
 Manipulate the mask associated with the nth parameter (e.g. More...
 
const Boolmask (const uInt n) const
 
const FunctionParam< T > & parameters () const
 Return the parameter interface. More...
 
FunctionParam< T > & parameters ()
 
const Vector< ArgType > & argp () const
 Get arg_p and parset_p. More...
 
Bool parsetp () const
 
void lockParam ()
 Compiler cannot always find the correct 'const' version of parameter access. More...
 
void unlockParam ()
 
virtual void setMode (const RecordInterface &mode)
 get/set the function mode. More...
 
virtual void getMode (RecordInterface &mode) const
 
virtual Bool hasMode () const
 return True if the implementing function supports a mode. More...
 
ostream & print (ostream &os) const
 Print the function (i.e. More...
 
- Public Member Functions inherited from casacore::Functional< FunctionTraits< T >::ArgType, T >
virtual ~Functional ()
 Destructor. More...
 
virtual T operator() (const FunctionTraits< T >::ArgType &x) const=0
 Map a Domain x into a Range y value. More...
 
- Public Member Functions inherited from casacore::Functional< Vector< FunctionTraits< T >::ArgType >, T >
virtual ~Functional ()
 Destructor. More...
 
virtual T operator() (const Vector< FunctionTraits< T >::ArgType > &x) const=0
 Map a Domain x into a Range y value. More...
 

Private Member Functions

void fromParam_p () const
 Copy the local parameters from general block. More...
 
void toParam_p ()
 Make the general block from local parameters. More...
 

Additional Inherited Members

- Public Types inherited from casacore::Function< T, U >
typedef FunctionTraits< T >::ArgType ArgType
 
typedef const ArgTypeFunctionArg
 
- Protected Attributes inherited from casacore::CompoundParam< T >
PtrBlock< Function< T > * > functionPtr_p
 Pointer to each added function. More...
 
Block< uIntparoff_p
 Index of offset for each function to its parameters in general list. More...
 
Block< uIntfunpar_p
 Index of function belonging to parameter. More...
 
Block< uIntlocpar_p
 Index of local parameter. More...
 
- Protected Attributes inherited from casacore::Function< T, U >
FunctionParam< T > param_p
 The parameters and masks. More...
 
Vector< ArgTypearg_p
 Aid for non-contiguous argument storage. More...
 
Bool parset_p
 Indicate parameter written. More...
 
Bool locked_p
 Indicate that parameters are expected to be locked from changing. More...
 

Detailed Description

template<class T>
class casacore::CompoundFunction< T >

Sum of a collection of Functions which behaves as one Function object.

Intended use:

Public interface

Review Status

Reviewed By:
tcornwel
Date Reviewed:
1996/02/22
Test programs:
tCompoundFunction

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 abd 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
CompoundParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
LatticeExprNode sum(const LatticeExprNode &expr)

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

Definition at line 114 of file CompoundFunction.h.

Constructor & Destructor Documentation

◆ CompoundFunction() [1/5]

template<class T >
casacore::CompoundFunction< T >::CompoundFunction ( )
inline

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

Definition at line 120 of file CompoundFunction.h.

◆ CompoundFunction() [2/5]

template<class T >
casacore::CompoundFunction< T >::CompoundFunction ( const CompoundFunction< T > &  other)
inline

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.

Definition at line 125 of file CompoundFunction.h.

◆ CompoundFunction() [3/5]

template<class T >
casacore::CompoundFunction< T >::CompoundFunction ( const CompoundFunction< T > &  other,
Bool   
)
inline

Definition at line 127 of file CompoundFunction.h.

◆ CompoundFunction() [4/5]

template<class T >
template<class W >
casacore::CompoundFunction< T >::CompoundFunction ( const CompoundFunction< W > &  other)
inline

Definition at line 130 of file CompoundFunction.h.

◆ CompoundFunction() [5/5]

template<class T >
template<class W >
casacore::CompoundFunction< T >::CompoundFunction ( const CompoundFunction< W > &  other,
Bool   
)
inline

Definition at line 133 of file CompoundFunction.h.

◆ ~CompoundFunction()

template<class T >
virtual casacore::CompoundFunction< T >::~CompoundFunction ( )
inlinevirtual

Destructor.

Definition at line 142 of file CompoundFunction.h.

Member Function Documentation

◆ clone()

template<class T >
virtual Function<T>* casacore::CompoundFunction< T >::clone ( ) const
inlinevirtual

Return a copy of this object from the heap.

The caller is responsible for deleting the pointer.

Implements casacore::Function< T, U >.

Definition at line 158 of file CompoundFunction.h.

References casacore::CompoundFunction< T >::fromParam_p().

◆ cloneAD()

template<class T >
virtual Function<typename FunctionTraits<T>::DiffType>* casacore::CompoundFunction< T >::cloneAD ( ) const
inlinevirtual

Reimplemented from casacore::Function< T, U >.

Definition at line 160 of file CompoundFunction.h.

◆ cloneNonAD()

template<class T >
virtual Function<typename FunctionTraits<T>::BaseType>* casacore::CompoundFunction< T >::cloneNonAD ( ) const
inlinevirtual

Reimplemented from casacore::Function< T, U >.

Definition at line 162 of file CompoundFunction.h.

References casacore::True.

◆ consolidate()

template<class T >
CompoundFunction<T>& casacore::CompoundFunction< T >::consolidate ( )
inline

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.

Definition at line 153 of file CompoundFunction.h.

References casacore::CompoundFunction< T >::fromParam_p(), and casacore::CompoundFunction< T >::toParam_p().

◆ eval()

template<class T >
virtual T casacore::CompoundFunction< T >::eval ( typename Function< T >::FunctionArg  x) const
virtual

Evaluate the function at x.

◆ fromParam_p()

template<class T >
void casacore::CompoundFunction< T >::fromParam_p ( ) const
private

◆ operator=()

template<class T >
CompoundFunction<T>& casacore::CompoundFunction< T >::operator= ( const CompoundFunction< T > &  other)
inline

Make this object a (deep) copy of other.

Definition at line 137 of file CompoundFunction.h.

References casacore::CompoundFunction< T >::fromParam_p(), and casacore::CompoundParam< T >::operator=().

◆ toParam_p()

template<class T >
void casacore::CompoundFunction< T >::toParam_p ( )
private

Make the general block from local parameters.

Referenced by casacore::CompoundFunction< T >::consolidate().


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