#include <Function.h>
Inheritance diagram for casa::Function< T, U >:


Part of API
A Function is used for classes which map a scalar or n-dimensional Vector of type T into a T. The object also has zero or more parameters which can be masked if necessary, and be used in the Fitting module, and, implicitly, in the AutoDiff differentiation module.
The parameter interface is provided by the FunctionParam class.
A Function can have a name() which can be used in generic interfaces.
The function calls implemented are:
operator()() operator()(const T &x) operator()(const Vector<T> &x) operator()(Function::FunctionArg x) operator()(const T &x, const T &y) (for 2D) operator()(const T &x, const T &y, const T &z) (for 3D) T in the above is the Function::ArgType as derived from the FunctionTraits class. These calls are (in debug mode) tested for the correct number of arguments, after which they call a T eval(FunctionArg x) const = 0 to be implemented in derived classes. The derived class should also implement an uInt ndim() const = 0. The derived class can access the nth parameter with the [n] operator, and the corresponding mask with mask(n) method. The variables are referenced with x[i].
A complete implementation of say an A.sin(2pi.f.x) with parameters amplitude(A) and frequency(f) and variable time(x) could be:
//# Sinusoid.h \#include <casa/aips.h> \#include <scimath/Functionals/Function.h> \#include <casa/BasicSL/Constants.h> \#include <casa/BasicMath/Math.h> // The sinusoid class template<class T> class Sinusoid : public Function<T> { public: // For easy reference of the parameters enum { AMPL=0, FREQ }; // Constructors. Defaults are A=1, f=1 Sinusoid() : Function<T>(2) { param_p[AMPL] = T(1.0); param_p[FREQ] = T(1.0); } explicit Sinusoid(const T &l) : Function<T>(2) { param_p[AMPL] = ampl; param_p[FREQ] = T(1.0); } Sinusoid(const T &l, const T &freq) : Function<T>(2) { param_p[AMPL] = ampl; param_p[FREQ] = freq; } Sinusoid(const Sinusoid &other) : Function<T>(2) { param_p[AMPL] = other.param_p[AMPL]; param_p[FREQ] = other.parameter[FREQ]; } Sinusoid<T> &operator=(const Sinusoid<T> &other) { if (this != &other) param_p = other.param_p; return *this; } virtual ~Sinusoid() {}; // Dimensionality virtual uInt ndim() const { return 2; }; // Evaluate virtual T eval(Function<T>::FunctionArg x) const { return param_p[AMPL]*sin(T(C::_2pi)*param_p[FREQ]*x[0]); }; // Copy it virtual Function<T> *clone() const { return new Sinusoid<T>(param_p); }; };
A=2; f=3; x=0.1; // The function objects for value, and for value + derivative Sinusoid<Double> soid1(2.0, 3.0); typedef AutoDiff<Double> Adif; Sinusoid<Adif> soid2(Adif(2,2,0), Adif(3,2,1)); cout << "Value: " << soid1(0.1) << endl; cout << "(val, deriv): " << soid2(Adif(0.1)) << endl;
A shorter version, where all parameter handling is done at user level could be:
//# Sinusoid.h \#include <casa/aips.h> \#include <scimath/Functionals/Function.h> \#include <casa/BasicSL/Constants.h> \#include <casa/BasicMath/Math.h> template<class T> class Sinusoid : public Function<T> { public: enum { AMPL=0, FREQ }; Sinusoid() : Function<T>(2){param_p[AMPL] T(1);param_p[FREQ]=T(1);} virtual ~Sinusoid() {}; virtual uInt ndim() const { return 2; }; virtual T eval(Function<T>::FunctionArg x) const { return param_p[AMPL]*sin(T(C::_2pi)*param_p[FREQ]*x[0]); }; virtual Function<T> *clone() const { return new Sinusoid<T>param_p; }; };
A=2; f=3; x=0.1; // The function objects for value, and for value + derivative typedef AutoDiff<Double> Adif; typedef Function<Double> FD; typedef Function<AutoDiff<Double> > FAdif Sinusoid<Double> soid1; Sinusoid<Adif> soid2; soid1[FD::AMPL] = 2; soid1[FD::FREQ] = 3; soid2[FAdif::AMPL] = Adif(2,2,0); soid2[FAdif::FREQ] = Adif(3,2,1); cout << "Value: " << soid1(0.1) << endl; cout << "(val, deriv): " << soid2(Adif(0.1)) << endl;
A function of more than one variable was required for a function which represents the sky brightness. Adjustable parameters were required for non-linear least squares fitting.
Vector<T>.
Definition at line 199 of file Function.h.
Public Types | |
| typedef FunctionTraits< T >::ArgType | ArgType |
| typedef const ArgType * | FunctionArg |
Public Member Functions | |
| virtual | ~Function () |
| Destructor. | |
| virtual uInt | ndim () const=0 |
| Returns the number of dimensions of function. | |
| uInt | nparameters () const |
| Returns the number of parameters. | |
| virtual U | eval (FunctionArg x) const =0 |
| Evaluate the function object. | |
| virtual const String & | name () const |
Specify the name associated with the function (default will be unknown). | |
| virtual Bool | hasMode () const |
| return True if the implementing function supports a mode. | |
| ostream & | print (ostream &os) const |
| Print the function (i.e. | |
| 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) | |
| Function (const Function< T, U > &other) | |
| 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. | |
| const 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 Function< T, U > * | clone () const=0 |
| 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 |
Protected Attributes | |
| 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. | |
| typedef FunctionTraits<T>::ArgType casa::Function< T, U >::ArgType |
Definition at line 205 of file Function.h.
| typedef const ArgType* casa::Function< T, U >::FunctionArg |
Definition at line 206 of file Function.h.
| casa::Function< T, U >::Function | ( | ) | [inline] |
| casa::Function< T, U >::Function | ( | const uInt | n | ) | [inline, explicit] |
Definition at line 212 of file Function.h.
| casa::Function< T, U >::Function | ( | const Vector< T > & | in | ) | [inline, explicit] |
Definition at line 214 of file Function.h.
| casa::Function< T, U >::Function | ( | const FunctionParam< T > & | other | ) | [inline] |
Definition at line 216 of file Function.h.
| casa::Function< T, U >::Function | ( | const Function< W, X > & | other | ) | [inline] |
Definition at line 219 of file Function.h.
| casa::Function< T, U >::Function | ( | const Function< T, U > & | other | ) | [inline] |
Definition at line 221 of file Function.h.
| virtual casa::Function< T, U >::~Function | ( | ) | [inline, virtual] |
| virtual uInt casa::Function< T, U >::ndim | ( | ) | const [pure virtual] |
Returns the number of dimensions of function.
Referenced by casa::Function< casa::AutoDiff< T > >::operator()(), and casa::GenericL2Fit< std::complex< Double > >::setConstraint().
| uInt casa::Function< T, U >::nparameters | ( | ) | const [inline] |
Returns the number of parameters.
Definition at line 231 of file Function.h.
Referenced by casa::ChebyshevParam< casa::AutoDiff< T > >::getCoefficient(), casa::ChebyshevParam< casa::AutoDiff< T > >::nCoefficients(), and casa::GenericL2Fit< std::complex< Double > >::setConstraint().
| virtual U casa::Function< T, U >::eval | ( | FunctionArg | x | ) | const [pure virtual] |
| T& casa::Function< T, U >::operator[] | ( | const uInt | n | ) | [inline] |
Manipulate the nth parameter (0-based) with no index check.
Definition at line 239 of file Function.h.
| const T& casa::Function< T, U >::operator[] | ( | const uInt | n | ) | const [inline] |
Definition at line 241 of file Function.h.
| virtual U casa::Function< T, U >::operator() | ( | ) | const [inline, virtual] |
Evaluate this function object at xor at x, y.
The length of x must be greater than or equal to ndim().
Definition at line 247 of file Function.h.
| virtual U casa::Function< T, U >::operator() | ( | const ArgType & | x | ) | const [inline, virtual] |
Definition at line 249 of file Function.h.
| virtual U casa::Function< T, U >::operator() | ( | const Vector< ArgType > & | x | ) | const [virtual] |
| virtual U casa::Function< T, U >::operator() | ( | FunctionArg | x | ) | const [inline, virtual] |
Definition at line 252 of file Function.h.
| virtual U casa::Function< T, U >::operator() | ( | const ArgType & | x, | |
| const ArgType & | y | |||
| ) | const [virtual] |
| virtual U casa::Function< T, U >::operator() | ( | const ArgType & | x, | |
| const ArgType & | y, | |||
| const ArgType & | z | |||
| ) | const [virtual] |
| virtual const String& casa::Function< T, U >::name | ( | ) | const [virtual] |
Specify the name associated with the function (default will be unknown).
| Bool& casa::Function< T, U >::mask | ( | const uInt | n | ) | [inline] |
Manipulate the mask associated with the nth parameter (e.g.
to indicate whether the parameter is adjustable or nonadjustable). Note: no index check.
Definition at line 267 of file Function.h.
| const Bool& casa::Function< T, U >::mask | ( | const uInt | n | ) | const [inline] |
Definition at line 269 of file Function.h.
| const FunctionParam<T>& casa::Function< T, U >::parameters | ( | ) | const [inline] |
| FunctionParam<T>& casa::Function< T, U >::parameters | ( | ) | [inline] |
Definition at line 274 of file Function.h.
| const Vector<ArgType>& casa::Function< T, U >::argp | ( | ) | const [inline] |
Get arg_p and parset_p.
Necessary for reasons of protection in the copying of non-conforming Functions.
Definition at line 279 of file Function.h.
| const Bool casa::Function< T, U >::parsetp | ( | ) | const [inline] |
Definition at line 280 of file Function.h.
| void casa::Function< T, U >::lockParam | ( | ) | [inline] |
Compiler cannot always find the correct 'const' version of parameter access.
In cases where this would lead to excessive overheads in moving parameters around (like in CompoundFunction) the parameter changing can be set to be locked, and no changes are assumed.
Definition at line 288 of file Function.h.
| void casa::Function< T, U >::unlockParam | ( | ) | [inline] |
Definition at line 289 of file Function.h.
| virtual void casa::Function< T, U >::setMode | ( | const RecordInterface & | mode | ) | [virtual] |
get/set the function mode.
These provide an interface to function-specific configuration or state that controls how the function calculates its values but otherwise does not qualify as a parameter. Some part of the state, for example, might have a type different from that of T. The state is passed as fields of a record, mode--the names, types and values of which are specific to the implementing function and should be documented in the implementing class. It is recommended that all possible inputs passed to this function via setMode() be considered optional such that if the record omits a legal field, that part of the state is left unchanged. Fields not recognized by the implementing class should be ignored. An exception should be thrown if a recognized field contains illegal data. The default implementations for both getMode() and setMode() ignore the input record.
| virtual void casa::Function< T, U >::getMode | ( | RecordInterface & | mode | ) | const [virtual] |
| virtual Bool casa::Function< T, U >::hasMode | ( | ) | const [virtual] |
return True if the implementing function supports a mode.
The default implementation returns False.
| ostream& casa::Function< T, U >::print | ( | ostream & | os | ) | const [inline] |
| virtual Function<T,U>* casa::Function< T, U >::clone | ( | ) | const [pure virtual] |
Return a copy of this object from the heap.
The caller is responsible for deleting this pointer. The cloneAD will return a clone with an AutoDef<T>; the cloneNonAD a clone with <T>. An AipsError will be thrown if the cloneAD() or cloneNonAD() is not implemented for a specific function.
| virtual Function<typename FunctionTraits<T>::DiffType>* casa::Function< T, U >::cloneAD | ( | ) | const [virtual] |
| virtual Function<typename FunctionTraits<T>::BaseType>* casa::Function< T, U >::cloneNonAD | ( | ) | const [virtual] |
FunctionParam<T> casa::Function< T, U >::param_p [protected] |
The parameters and masks.
Definition at line 333 of file Function.h.
Referenced by casa::Sinusoid1DParam< casa::AutoDiff< T > >::amplitude(), casa::Gaussian1DParam< casa::AutoDiff< T > >::center(), casa::EvenPolynomialParam< casa::AutoDiff< T > >::coefficient(), casa::PolynomialParam< casa::AutoDiff< T > >::coefficient(), casa::OddPolynomialParam< casa::AutoDiff< T > >::coefficient(), casa::SimButterworthBandpass< T >::getCenter(), casa::ChebyshevParam< casa::AutoDiff< T > >::getCoefficient(), casa::SimButterworthBandpass< T >::getMaxCutoff(), casa::SimButterworthBandpass< T >::getMinCutoff(), casa::SimButterworthBandpass< T >::getPeak(), casa::Gaussian1DParam< casa::AutoDiff< T > >::height(), casa::Function< casa::AutoDiff< T > >::mask(), casa::Function< casa::AutoDiff< T > >::nparameters(), casa::PolynomialParam< casa::AutoDiff< T > >::operator!=(), casa::EvenPolynomialParam< casa::AutoDiff< T > >::operator!=(), casa::OddPolynomialParam< casa::AutoDiff< T > >::operator!=(), casa::OddPolynomialParam< casa::AutoDiff< T > >::operator==(), casa::EvenPolynomialParam< casa::AutoDiff< T > >::operator==(), casa::PolynomialParam< casa::AutoDiff< T > >::operator==(), casa::Function< casa::AutoDiff< T > >::operator[](), casa::OddPolynomialParam< casa::AutoDiff< T > >::order(), casa::PolynomialParam< casa::AutoDiff< T > >::order(), casa::EvenPolynomialParam< casa::AutoDiff< T > >::order(), casa::ChebyshevParam< casa::AutoDiff< T > >::order(), casa::Function< casa::AutoDiff< T > >::parameters(), casa::Sinusoid1DParam< casa::AutoDiff< T > >::period(), casa::Function< casa::AutoDiff< T > >::print(), casa::Sinusoid1DParam< casa::AutoDiff< T > >::setAmplitude(), casa::Gaussian1DParam< casa::AutoDiff< T > >::setCenter(), casa::SimButterworthBandpass< T >::setCenter(), casa::EvenPolynomialParam< casa::AutoDiff< T > >::setCoefficient(), casa::PolynomialParam< casa::AutoDiff< T > >::setCoefficient(), casa::OddPolynomialParam< casa::AutoDiff< T > >::setCoefficient(), casa::Gaussian1DParam< casa::AutoDiff< T > >::setHeight(), casa::SimButterworthBandpass< T >::setMaxCutoff(), casa::SimButterworthBandpass< T >::setMinCutoff(), casa::SimButterworthBandpass< T >::setPeak(), casa::Sinusoid1DParam< casa::AutoDiff< T > >::setPeriod(), casa::Gaussian1DParam< casa::AutoDiff< T > >::setWidth(), casa::Sinusoid1DParam< casa::AutoDiff< T > >::setX0(), casa::Gaussian1DParam< casa::AutoDiff< T > >::width(), and casa::Sinusoid1DParam< casa::AutoDiff< T > >::x0().
Vector<ArgType> casa::Function< T, U >::arg_p [mutable, protected] |
Aid for non-contiguous argument storage.
Definition at line 335 of file Function.h.
Referenced by casa::Function< casa::AutoDiff< T > >::argp().
Bool casa::Function< T, U >::parset_p [mutable, protected] |
Indicate parameter written.
Definition at line 337 of file Function.h.
Referenced by casa::Function< casa::AutoDiff< T > >::mask(), casa::Function< casa::AutoDiff< T > >::operator[](), casa::Function< casa::AutoDiff< T > >::parameters(), and casa::Function< casa::AutoDiff< T > >::parsetp().
Bool casa::Function< T, U >::locked_p [mutable, protected] |
Indicate that parameters are expected to be locked from changing.
Definition at line 339 of file Function.h.
Referenced by casa::Function< casa::AutoDiff< T > >::lockParam(), casa::Function< casa::AutoDiff< T > >::mask(), casa::Function< casa::AutoDiff< T > >::operator[](), and casa::Function< casa::AutoDiff< T > >::unlockParam().
1.5.1