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> class CombiParam : public Function<T>
109{
110public:
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),
121 for (uInt i=0; i<functionPtr_p.nelements(); ++i) {
122 functionPtr_p[i] = (*(other.functionPtr_p[i])).clone();
123 }
124 }
125 template <class W>
126 CombiParam(const CombiParam<W> &other) :
127 Function<T>(other), ndim_p(other.ndim()),
128 functionPtr_p(other.nFunctions()) {
129 for (uInt i=0; i<nFunctions(); ++i) {
130 functionPtr_p[i] = other.function(i).cloneAD();
131 }
132 }
133 template <class W>
135 Function<T>(other), ndim_p(other.ndim()),
136 functionPtr_p(other.nFunctions()) {
137 for (uInt i=0; i<nFunctions(); ++i) {
138 functionPtr_p[i] = other.function(i).cloneNonAD();
139 }
140 }
141 // </group>
142 // Make this object a (deep) copy of other.
144 // Destructor
145 virtual ~CombiParam();
146
147 //# Operators
148
149 //# Member functions
150 // Give name of function
151 virtual const String &name() const { static String x("combi");
152 return x; }
153
154 // Add a function. All functions must have the same <src>ndim()</src>
155 // as the first one. Returns the (zero relative) number (<src>i</src>)
156 // of the function just added.
157 // The default initial parameter value (<src>a(i)</src>) is
158 // initialized to 1. The parameter mask is set <src>True</src>.
159 uInt addFunction(const Function<T> &newFunction);
160
161 // Return the total number of functions. The number is equal to the
162 // number of functions that have been added.
163 uInt nFunctions() const { return nparameters(); }
164
165 // Return a reference to a specific Function in the combination.
166 // <group>
167 const Function<T> &function(uInt which) const {
168 DebugAssert(nFunctions() > which, AipsError);
169 return *(functionPtr_p[which]); }
170 const Function<T> &function(uInt which) {
171 DebugAssert(nFunctions() > which, AipsError);
172 return *(functionPtr_p[which]); }
173 // </group>
174
175 // Returns the dimension of functions in the linear combination
176 virtual uInt ndim() const { return ndim_p; }
177
178protected:
179 //# Data
180 // Number of dimensions of underlying functions
182
183 // Pointer to each added function
185
186 //# Make members of parent classes known.
187public:
188 using Function<T>::nparameters;
189};
190
191
192} //# NAMESPACE CASACORE - END
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:183
const Function< T > & function(uInt which) const
Return a reference to a specific Function in the combination.
Definition CombiParam.h:167
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:151
virtual uInt ndim() const
Returns the dimension of functions in the linear combination.
Definition CombiParam.h:176
uInt addFunction(const Function< T > &newFunction)
Add a function.
uInt ndim_p
Number of dimensions of underlying functions.
Definition CombiParam.h:181
uInt nFunctions() const
Return the total number of functions.
Definition CombiParam.h:163
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
PtrBlock< Function< T > * > functionPtr_p
Pointer to each added function.
Definition CombiParam.h:184
CombiParam(const CombiParam< W > &other)
Definition CombiParam.h:126
CombiParam(const CombiParam< T > &other, Bool)
Definition CombiParam.h:118
CombiParam(const CombiParam< W > &other, Bool)
Definition CombiParam.h:134
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.
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:228
A drop-in replacement for Block<T*>.
Definition Block.h:812
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
LatticeExprNode nelements(const LatticeExprNode &expr)
1-argument function to get the number of elements in a lattice.