casacore
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: aips2-request@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 //#
27 //# $Id$
28 
29 #ifndef SCIMATH_COMBIFUNCTION_H
30 #define SCIMATH_COMBIFUNCTION_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/scimath/Functionals/CombiParam.h>
35 #include <casacore/scimath/Mathematics/AutoDiff.h>
36 #include <casacore/scimath/Mathematics/AutoDiffMath.h>
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 //# Forward declarations
41 
42 // <summary>
43 // Form a linear combination of function objects.
44 // </summary>
45 //
46 // <use visibility=export>
47 //
48 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tCombiFunction" demos="">
49 // </reviewed>
50 //
51 // <prerequisite>
52 // <li> <linkto class="Function">Function</linkto> class
53 // </prerequisite>
54 //
55 // <synopsis>
56 // Given N function objects, the class describes a linear combination of the
57 // form:
58 // <srcblock>
59 // f(x) = a(0)*f(0)(x) + a(1)*f(1)(x) + ... + a(N-1)*f(N-1)(x)
60 // </srcblock>
61 // where a = {a(n)} are parameters. If the combi function is used in
62 // a functional fitting process (see
63 // <linkto class=LinearFit>LinearFit</linkto>) these parameters canm be
64 // solved for. In all aspects they behave as
65 // <linkto class=FunctionParam>FunctionParam</linkto> values.
66 //
67 // Member functions are added with the <src>addFunction()</src> method.
68 //
69 // <note role=tip>
70 // Check <linkto class=CompoundFunction>CompoundFunction</linkto> class
71 // for a combination of functions behaving as one object. </note>
72 // </synopsis>
73 //
74 // <example>
75 // In the following example a second order polynomial is built from 3 separate
76 // polynomials.
77 // <srcblock>
78 // Polynomial<Double> constant(0);
79 // Polynomial<Double> linear(1);
80 // Polynomial<Double> square(2);
81 //
82 // constant.setCoefficient(0, 1.0); // 1
83 // linear.setCoefficient(1, 1.0); // x
84 // square[2] = 1.0; // x^2
85 //
86 // CombiFunction<Double> combination;
87 //
88 // // form function, e0 + e1*x + e2*x^2
89 // combination.addFunction(constant);
90 // combination.addFunction(linear);
91 // combination.addFunction(square);
92 // </srcblock>
93 // </example>
94 
95 // <templating arg=T>
96 // <li> T should have standard numerical operators and exp() function. Current
97 // implementation only tested for real types.
98 // <li> To obtain derivatives, the derivatives should be defined.
99 // </templating>
100 
101 // <thrown>
102 // <li> AipsError in debug mode if incorrect function index
103 // </thrown>
104 //
105 // <motivation>
106 // This class was created to allow specialization of the evaluation in
107 // a simple way.
108 // </motivation>
109 //
110 // <todo asof="2001/10/22">
111 // <li> Nothing I know of
112 // </todo>
113 
114 template <class T> class CombiFunction : public CombiParam<T> {
115  public:
116  //# Constructors
117  // The default constructor -- no functions, no parameters, nothing, the
118  // function operator returns a 0.
120  // Make this object a (deep) copy of other.
121  // <group>
123  CombiParam<T>(other) {}
125  CombiParam<T>(other, True) {}
126  template <class W>
127  CombiFunction(const CombiFunction<W> &other) : CombiParam<T>(other) {}
128  template <class W>
130  CombiParam<T>(other, True) {}
131  // </group>
132  // Make this object a (deep) copy of other.
134  CombiParam<T>::operator=(other); return *this; }
135 
136  // Destructor
137  virtual ~CombiFunction() {}
138 
139  //# Operators
140  // Evaluate the function at <src>x</src>.
141  virtual T eval(typename Function<T>::FunctionArg x) const;
142 
143  //# Member functions
144  // Return a copy of this object from the heap. The caller is responsible for
145  // deleting the pointer.
146  // <group>
147  virtual Function<T> *clone() const { return new CombiFunction<T>(*this); }
152  (*this, True); }
153  // </group>
154 
155  //# Make members of parent classes known.
156 public:
158 };
159 
160 #define CombiFunction_PS CombiFunction
161 
162 // <summary> Partial specialization of CombiFunction for <src>AutoDiff</src>
163 // </summary>
164 
165 // <synopsis>
166 // <note role=warning> The name <src>CombiFunction_PS</src> is only for cxx2html
167 // documentation problems. Use <src>CombiFunction</src> in your code.</note>
168 // </synopsis>
169 
170 template <class T> class CombiFunction_PS<AutoDiff<T> > :
171 public CombiParam<AutoDiff<T> > {
172  public:
173  //# Constructors
174  // The default constructor -- no functions, no parameters, nothing, the
175  // function operator returns a 0.
176  CombiFunction_PS() : CombiParam<AutoDiff<T> >() {}
177  // Make this object a (deep) copy of other.
178  // <group>
180  CombiParam<AutoDiff<T> >(other) {}
181  template <class W>
182  CombiFunction_PS(const CombiFunction_PS<W> &other) :
183  CombiParam<AutoDiff<T> >(other) {}
184  // </group>
185  // Make this object a (deep) copy of other.
186  CombiFunction_PS<AutoDiff<T> > &
187  operator=(const CombiFunction_PS<AutoDiff<T> > &other) {
188  CombiParam<AutoDiff<T> >::operator=(other); return *this; }
189 
190  // Destructor
191  virtual ~CombiFunction_PS() {}
192 
193  //# Operators
194  // Evaluate the function and its derivatives at <src>x</src> <em>wrt</em>
195  // to the coefficients.
196  virtual AutoDiff<T> eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
197 
198  //# Member functions
199  // Return a copy of this object from the heap. The caller is responsible for
200  // deleting the pointer.
201  // <group>
202  virtual Function<AutoDiff<T> > *clone() const {
203  return new CombiFunction_PS<AutoDiff<T> >(*this); }
205  *cloneAD() const {
207  (*this); }
209  *cloneNonAD() const {
211  (*this, True); }
212  // </group>
213 
214  //# Make members of parent classes known.
215 public:
216  using CombiParam<AutoDiff<T> >::nparameters;
217 };
218 
219 #undef CombiFunction_PS
220 
221 
222 } //# NAMESPACE CASACORE - END
223 
224 #ifndef CASACORE_NO_AUTO_TEMPLATES
225 #include <casacore/scimath/Functionals/CombiFunction.tcc>
226 #include <casacore/scimath/Functionals/Combi2Function.tcc>
227 #endif //# CASACORE_NO_AUTO_TEMPLATES
228 #endif
#define CombiFunction_PS
CombiFunction()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
CombiFunction(const CombiFunction< T > &other, Bool)
CombiFunction< T > & operator=(const CombiFunction< T > &other)
Make this object a (deep) copy of other.
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the function at x.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
CombiFunction(const CombiFunction< T > &other)
Make this object a (deep) copy of other.
CombiFunction(const CombiFunction< W > &other)
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
virtual ~CombiFunction()
Destructor.
CombiFunction(const CombiFunction< W > &other, Bool)
CombiParam< T > & operator=(const CombiParam< T > &other)
Make this object a (deep) copy of other.
const ArgType * FunctionArg
Definition: Function.h:207
this file contains all the compiler specific defines
Definition: mainpage.dox:28
PtrHolder< T > & operator=(const PtrHolder< T > &other)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43