Loading...
Searching...
No Matches
casacore::CompoundFunction< T > Class Template Reference
scimath package (libcasa_scimath) » Functionals_module

More...

`#include <CompoundFunction.h>`

## Public Member Functions

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

## Private Member Functions

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

## Additional Inherited Members

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

## 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

- Function class

### 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
casacore::CompoundParam::CompoundParam
CompoundParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
casacore::Gaussian1D
Definition Gaussian1D.h:133
casacore::Polynomial
Polynomial()
Definition Polynomial.h:94
casacore::sum
LatticeExprNode sum(const LatticeExprNode &expr)

### Template Type Argument Requirements (T)

- T should have standard numerical operators and exp() function. Current implementation only tested for real types.
- To obtain derivatives, the derivatives should be defined.

### Thrown Exceptions

- AipsError if dimensions of functions added different

### 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

- Nothing I know of

Definition at line 111 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 117 of file CompoundFunction.h.

References casacore::CompoundParam< T >::CompoundParam().

Referenced by clone(), cloneAD(), cloneNonAD(), CompoundFunction(), CompoundFunction(), CompoundFunction(), CompoundFunction(), consolidate(), and operator=().

## 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 122 of file CompoundFunction.h.

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

## CompoundFunction() [3/5]

template<class T>

casacore::CompoundFunction< T >::CompoundFunction | ( | const CompoundFunction< T > & | other,
|  | Bool | )

inline

Definition at line 124 of file CompoundFunction.h.

References CompoundFunction(), casacore::CompoundParam< T >::CompoundParam(), and casacore::True.

## CompoundFunction() [4/5]

template<class T>
template<class W>

casacore::CompoundFunction< T >::CompoundFunction | ( | const CompoundFunction< W > & | other | ) |

inline

Definition at line 127 of file CompoundFunction.h.

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

## CompoundFunction() [5/5]

template<class T>
template<class W>

casacore::CompoundFunction< T >::CompoundFunction | ( | const CompoundFunction< W > & | other,
|  | Bool | )

inline

Definition at line 130 of file CompoundFunction.h.

References CompoundFunction(), casacore::CompoundParam< T >::CompoundParam(), and casacore::True.

## ~CompoundFunction()

template<class T>

virtual casacore::CompoundFunction< T >::~CompoundFunction | ( |  | ) |

inline virtual

Destructor.

Definition at line 139 of file CompoundFunction.h.

## Member Function Documentation

## clone()

template<class T>

virtual Function< T > * casacore::CompoundFunction< T >::clone | ( |  | ) | const

inline virtual

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 155 of file CompoundFunction.h.

References CompoundFunction(), and fromParam_p().

## cloneAD()

template<class T>

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

inline virtual

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

Definition at line 157 of file CompoundFunction.h.

References CompoundFunction().

## cloneNonAD()

template<class T>

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

inline virtual

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

Definition at line 159 of file CompoundFunction.h.

References CompoundFunction(), and 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 150 of file CompoundFunction.h.

References CompoundFunction(), fromParam_p(), and 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

Copy the local parameters from general block.

Referenced by clone(), consolidate(), and operator=().

## 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 134 of file CompoundFunction.h.

References CompoundFunction(), 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.

References casacore::CompoundParam< T >::CompoundParam(), casacore::CompoundParam< T >::function(), casacore::CompoundParam< T >::functionPtr_p, casacore::CompoundParam< T >::funpar_p, casacore::CompoundParam< T >::locpar_p, casacore::CompoundParam< T >::nFunctions(), casacore::Function< T, U >::nparameters(), casacore::Function< T, U >::param_p, casacore::CompoundParam< T >::paroff_p, and casacore::Function< T, U >::parset_p.

Referenced by consolidate().

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

- scimath/Functionals/CompoundFunction.h