casacore
Loading...
Searching...
No Matches
CombiParam.h
Go to the documentation of this file.
1// # CombiParam.h: Parameters for 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_COMBIPARAM_H
27#define SCIMATH_COMBIPARAM_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/BasicSL/String.h>
32#include <casacore/casa/Containers/Block.h>
33#include <casacore/casa/Utilities/Assert.h>
34#include <casacore/scimath/Functionals/Function.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// # Forward declarations
39
40// <summary>
41// Parameters for a linear combination of function objects.
42// </summary>
43//
44// <use visibility=local>
45//
46// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tCombiFunction" demos="">
47// </reviewed>
48//
49// <prerequisite>
50// <li> <linkto class="CombiFunction">CombiFunction</linkto> class
51// </prerequisite>
52//
53// <synopsis>
54// Given N function objects, the class describes a linear combination of the
55// form:
56// <srcblock>
57// f(x) = a(0)*f(0)(x) + a(1)*f(1)(x) + ... + a(N-1)*f(N-1)(x)
58// </srcblock>
59// where a = {a(n)} are parameters. If the combi function is used in
60// a functional fitting process (see
61// <linkto class=LinearFit>LinearFit</linkto>) these parameters canm be
62// solved for. In all aspects they behave as
63// <linkto class=FunctionParam>FunctionParam</linkto> values.
64//
65// Member functions are added with the <src>addFunction()</src> method.
66// </synopsis>
67//
68// <example>
69// In the following example a second order polynomial is built from 3 separate
70// polynomials.
71// <srcblock>
72// Polynomial<Double> constant(0);
73// Polynomial<Double> linear(1);
74// Polynomial<Double> square(2);
75//
76// constant.setCoefficient(0, 1.0); // 1
77// linear.setCoefficient(1, 1.0); // x
78// square[2] = 1.0; // x^2
79//
80// CombiParam<Double> combination;
81//
82// // form function, e0 + e1*x + e2*x^2
83// combination.addFunction(constant);
84// combination.addFunction(linear);
85// combination.addFunction(square);
86// </srcblock>
87// </example>
88
89// <templating arg=T>
90// <li> T should have standard numerical operators and exp() function. Current
91// implementation only tested for real types.
92// <li> To obtain derivatives, the derivatives should be defined.
93// </templating>
94
95// <thrown>
96// <li> AipsError if dimensions of functions added different
97// </thrown>
98
99// <motivation>
100// This class was created to allow specialization of the evaluation in
101// a simple way.
102// </motivation>
103//
104// <todo asof="2001/10/22">
105// <li> Nothing I know of
106// </todo>
107
108template <class T>
109class CombiParam : public Function<T> {
110 public:
111 // # Constructors
112 // The default constructor -- no functions, no parameters, nothing, the
113 // function operator returns a 0.
115 // Make this object a (deep) copy of other.
116 // <group>
119 : Function<T>(other), ndim_p(other.ndim_p), functionPtr_p(other.functionPtr_p.nelements()) {
120 for (uInt i = 0; i < functionPtr_p.nelements(); ++i) {
121 functionPtr_p[i] = (*(other.functionPtr_p[i])).clone();
122 }
123 }
124 template <class W>
126 : Function<T>(other), ndim_p(other.ndim()), functionPtr_p(other.nFunctions()) {
127 for (uInt i = 0; i < nFunctions(); ++i) {
128 functionPtr_p[i] = other.function(i).cloneAD();
129 }
130 }
131 template <class W>
133 : Function<T>(other), ndim_p(other.ndim()), functionPtr_p(other.nFunctions()) {
134 for (uInt i = 0; i < nFunctions(); ++i) {
135 functionPtr_p[i] = other.function(i).cloneNonAD();
136 }
137 }
138 // </group>
139 // Make this object a (deep) copy of other.
141 // Destructor
142 virtual ~CombiParam();
143
144 // # Operators
145
146 // # Member functions
147 // Give name of function
148 virtual const String &name() const {
149 static String x("combi");
150 return x;
151 }
152
153 // Add a function. All functions must have the same <src>ndim()</src>
154 // as the first one. Returns the (zero relative) number (<src>i</src>)
155 // of the function just added.
156 // The default initial parameter value (<src>a(i)</src>) is
157 // initialized to 1. The parameter mask is set <src>True</src>.
158 uInt addFunction(const Function<T> &newFunction);
159
160 // Return the total number of functions. The number is equal to the
161 // number of functions that have been added.
162 uInt nFunctions() const { return nparameters(); }
163
164 // Return a reference to a specific Function in the combination.
165 // <group>
166 const Function<T> &function(uInt which) const {
167 DebugAssert(nFunctions() > which, AipsError);
168 return *(functionPtr_p[which]);
169 }
170 const Function<T> &function(uInt which) {
171 DebugAssert(nFunctions() > which, AipsError);
172 return *(functionPtr_p[which]);
173 }
174 // </group>
175
176 // Returns the dimension of functions in the linear combination
177 virtual uInt ndim() const { return ndim_p; }
178
179 protected:
180 // # Data
181 // Number of dimensions of underlying functions
183
184 // Pointer to each added function
186
187 // # Make members of parent classes known.
188 public:
189 using Function<T>::nparameters;
190};
191
192} // namespace casacore
193
194#ifndef CASACORE_NO_AUTO_TEMPLATES
195#include <casacore/scimath/Functionals/CombiParam.tcc>
196#endif // # CASACORE_NO_AUTO_TEMPLATES
197#endif
#define DebugAssert(expr, exception)
Definition Assert.h:161
const Function< T > & function(uInt which) const
Return a reference to a specific Function in the combination.
Definition CombiParam.h:166
CombiParam(const CombiParam< T > &other)
Make this object a (deep) copy of other.
virtual const String & name() const
Give name of function.
Definition CombiParam.h:148
virtual uInt ndim() const
Returns the dimension of functions in the linear combination.
Definition CombiParam.h:177
uInt addFunction(const Function< T > &newFunction)
Add a function.
Block< Function< T > * > functionPtr_p
Pointer to each added function.
Definition CombiParam.h:185
uInt ndim_p
Number of dimensions of underlying functions.
Definition CombiParam.h:182
uInt nFunctions() const
Return the total number of functions.
Definition CombiParam.h:162
virtual ~CombiParam()
Destructor.
CombiParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0.
const Function< T > & function(uInt which)
Definition CombiParam.h:170
CombiParam(const CombiParam< W > &other)
Definition CombiParam.h:125
CombiParam(const CombiParam< T > &other, Bool)
Definition CombiParam.h:118
CombiParam(const CombiParam< W > &other, Bool)
Definition CombiParam.h:132
CombiParam< T > & operator=(const CombiParam< T > &other)
Make this object a (deep) copy of other.
virtual Function< T, U > * clone() const =0
Return a copy of this object from the heap.
Function()
Constructors.
Definition Function.h:209
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:226
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
size_t nelements() const
The number of elements contained in this Block<T>.
Definition Block.h:565
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40