casacore
Loading...
Searching...
No Matches
CombiFunction.h
Go to the documentation of this file.
1// # CombiFunction.h: Form a linear combination of Functions
2// # Copyright (C) 2001,2002,2005
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef SCIMATH_COMBIFUNCTION_H
27#define SCIMATH_COMBIFUNCTION_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/CombiParam.h>
32#include <casacore/scimath/Mathematics/AutoDiff.h>
33#include <casacore/scimath/Mathematics/AutoDiffMath.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward declarations
38
39// <summary>
40// Form a linear combination of function objects.
41// </summary>
42//
43// <use visibility=export>
44//
45// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tCombiFunction" demos="">
46// </reviewed>
47//
48// <prerequisite>
49// <li> <linkto class="Function">Function</linkto> class
50// </prerequisite>
51//
52// <synopsis>
53// Given N function objects, the class describes a linear combination of the
54// form:
55// <srcblock>
56// f(x) = a(0)*f(0)(x) + a(1)*f(1)(x) + ... + a(N-1)*f(N-1)(x)
57// </srcblock>
58// where a = {a(n)} are parameters. If the combi function is used in
59// a functional fitting process (see
60// <linkto class=LinearFit>LinearFit</linkto>) these parameters canm be
61// solved for. In all aspects they behave as
62// <linkto class=FunctionParam>FunctionParam</linkto> values.
63//
64// Member functions are added with the <src>addFunction()</src> method.
65//
66// <note role=tip>
67// Check <linkto class=CompoundFunction>CompoundFunction</linkto> class
68// for a combination of functions behaving as one object. </note>
69// </synopsis>
70//
71// <example>
72// In the following example a second order polynomial is built from 3 separate
73// polynomials.
74// <srcblock>
75// Polynomial<Double> constant(0);
76// Polynomial<Double> linear(1);
77// Polynomial<Double> square(2);
78//
79// constant.setCoefficient(0, 1.0); // 1
80// linear.setCoefficient(1, 1.0); // x
81// square[2] = 1.0; // x^2
82//
83// CombiFunction<Double> combination;
84//
85// // form function, e0 + e1*x + e2*x^2
86// combination.addFunction(constant);
87// combination.addFunction(linear);
88// combination.addFunction(square);
89// </srcblock>
90// </example>
91
92// <templating arg=T>
93// <li> T should have standard numerical operators and exp() function. Current
94// implementation only tested for real types.
95// <li> To obtain derivatives, the derivatives should be defined.
96// </templating>
97
98// <thrown>
99// <li> AipsError in debug mode if incorrect function index
100// </thrown>
101//
102// <motivation>
103// This class was created to allow specialization of the evaluation in
104// a simple way.
105// </motivation>
106//
107// <todo asof="2001/10/22">
108// <li> Nothing I know of
109// </todo>
110
111template <class T>
112class CombiFunction : public CombiParam<T> {
113 public:
114 // # Constructors
115 // The default constructor -- no functions, no parameters, nothing, the
116 // function operator returns a 0.
118 // Make this object a (deep) copy of other.
119 // <group>
120 CombiFunction(const CombiFunction<T> &other) : CombiParam<T>(other) {}
121 CombiFunction(const CombiFunction<T> &other, Bool) : CombiParam<T>(other, True) {}
122 template <class W>
123 CombiFunction(const CombiFunction<W> &other) : CombiParam<T>(other) {}
124 template <class W>
125 CombiFunction(const CombiFunction<W> &other, Bool) : CombiParam<T>(other, True) {}
126 // </group>
127 // Make this object a (deep) copy of other.
130 return *this;
131 }
132
133 // Destructor
134 virtual ~CombiFunction() {}
135
136 // # Operators
137 // Evaluate the function at <src>x</src>.
138 virtual T eval(typename Function<T>::FunctionArg x) const;
139
140 // # Member functions
141 // Return a copy of this object from the heap. The caller is responsible for
142 // deleting the pointer.
143 // <group>
144 virtual Function<T> *clone() const { return new CombiFunction<T>(*this); }
151 // </group>
152
153 // # Make members of parent classes known.
154 public:
156};
157
158#define CombiFunction_PS CombiFunction
159
160// <summary> Partial specialization of CombiFunction for <src>AutoDiff</src>
161// </summary>
162
163// <synopsis>
164// <note role=warning> The name <src>CombiFunction_PS</src> is only for cxx2html
165// documentation problems. Use <src>CombiFunction</src> in your code.</note>
166// </synopsis>
167
168template <class T>
169class CombiFunction_PS<AutoDiff<T>> : public CombiParam<AutoDiff<T>> {
170 public:
171 // # Constructors
172 // The default constructor -- no functions, no parameters, nothing, the
173 // function operator returns a 0.
175 // Make this object a (deep) copy of other.
176 // <group>
178 template <class W>
179 CombiFunction_PS(const CombiFunction_PS<W> &other) : CombiParam<AutoDiff<T>>(other) {}
180 // </group>
181 // Make this object a (deep) copy of other.
183 CombiParam<AutoDiff<T>>::operator=(other);
184 return *this;
185 }
186
187 // Destructor
188 virtual ~CombiFunction_PS() {}
189
190 // # Operators
191 // Evaluate the function and its derivatives at <src>x</src> <em>wrt</em>
192 // to the coefficients.
193 virtual AutoDiff<T> eval(typename Function<AutoDiff<T>>::FunctionArg x) const;
194
195 // # Member functions
196 // Return a copy of this object from the heap. The caller is responsible for
197 // deleting the pointer.
198 // <group>
199 virtual Function<AutoDiff<T>> *clone() const { return new CombiFunction_PS<AutoDiff<T>>(*this); }
200 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
201 return new CombiFunction<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
203 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
204 return new CombiFunction<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this, True);
205 }
206 // </group>
207
208 // # Make members of parent classes known.
209 public:
210 using CombiParam<AutoDiff<T>>::nparameters;
211};
212
213#undef CombiFunction_PS
214
215} // namespace casacore
216
217#ifndef CASACORE_NO_AUTO_TEMPLATES
218#include <casacore/scimath/Functionals/CombiFunction.tcc>
219#include <casacore/scimath/Functionals/Combi2Function.tcc>
220#endif // # CASACORE_NO_AUTO_TEMPLATES
221#endif
#define CombiFunction_PS
CombiFunction_PS< AutoDiff< T > > & operator=(const CombiFunction_PS< AutoDiff< T > > &other)
Make this object a (deep) copy of other.
CombiFunction_PS()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
CombiFunction_PS(const CombiFunction_PS< W > &other)
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
CombiFunction_PS(const CombiFunction_PS< AutoDiff< T > > &other)
Make this object a (deep) copy of other.
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
Evaluate the function and its derivatives at x wrt to the coefficients.
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
CombiFunction()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
CombiFunction(const CombiFunction< T > &other, Bool)
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the function at x.
CombiFunction(const CombiFunction< T > &other)
Make this object a (deep) copy of other.
CombiFunction(const CombiFunction< W > &other)
CombiFunction< T > & operator=(const CombiFunction< T > &other)
Make this object a (deep) copy of other.
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
virtual ~CombiFunction()
Destructor.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
CombiFunction(const CombiFunction< W > &other, Bool)
CombiParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
CombiParam< T > & operator=(const CombiParam< T > &other)
Make this object a (deep) copy of other.
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:226
const ArgType * FunctionArg
Definition Function.h:204
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:126
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:129