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> class CombiFunction : public CombiParam<T> {
112 public:
113 //# Constructors
114 // The default constructor -- no functions, no parameters, nothing, the
115 // function operator returns a 0.
117 // Make this object a (deep) copy of other.
118 // <group>
120 CombiParam<T>(other) {}
122 CombiParam<T>(other, True) {}
123 template <class W>
124 CombiFunction(const CombiFunction<W> &other) : CombiParam<T>(other) {}
125 template <class W>
127 CombiParam<T>(other, True) {}
128 // </group>
129 // Make this object a (deep) copy of other.
131 CombiParam<T>::operator=(other); return *this; }
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); }
150 // </group>
151
152 //# Make members of parent classes known.
153public:
155};
156
157#define CombiFunction_PS CombiFunction
158
159// <summary> Partial specialization of CombiFunction for <src>AutoDiff</src>
160// </summary>
161
162// <synopsis>
163// <note role=warning> The name <src>CombiFunction_PS</src> is only for cxx2html
164// documentation problems. Use <src>CombiFunction</src> in your code.</note>
165// </synopsis>
167template <class T> class CombiFunction_PS<AutoDiff<T> > :
168public CombiParam<AutoDiff<T> > {
169 public:
170 //# Constructors
171 // The default constructor -- no functions, no parameters, nothing, the
172 // function operator returns a 0.
174 // Make this object a (deep) copy of other.
175 // <group>
177 CombiParam<AutoDiff<T> >(other) {}
178 template <class W>
179 CombiFunction_PS(const CombiFunction_PS<W> &other) :
180 CombiParam<AutoDiff<T> >(other) {}
181 // </group>
182 // Make this object a (deep) copy of other.
183 CombiFunction_PS<AutoDiff<T> > &
184 operator=(const CombiFunction_PS<AutoDiff<T> > &other) {
185 CombiParam<AutoDiff<T> >::operator=(other); return *this; }
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 {
200 return new CombiFunction_PS<AutoDiff<T> >(*this); }
202 *cloneAD() const {
204 (*this); }
206 *cloneNonAD() const {
208 (*this, True); }
209 // </group>
210
211 //# Make members of parent classes known.
212public:
213 using CombiParam<AutoDiff<T> >::nparameters;
214};
215
216#undef CombiFunction_PS
217
218
219} //# NAMESPACE CASACORE - END
220
221#ifndef CASACORE_NO_AUTO_TEMPLATES
222#include <casacore/scimath/Functionals/CombiFunction.tcc>
223#include <casacore/scimath/Functionals/Combi2Function.tcc>
224#endif //# CASACORE_NO_AUTO_TEMPLATES
225#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< 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:228
this file contains all the compiler specific defines
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
PtrHolder< T > & operator=(const PtrHolder< T > &other)