casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: 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_COMBIPARAM_H
30 #define SCIMATH_COMBIPARAM_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 //# Forward declarations
42 
43 // <summary>
44 // Parameters for a linear combination of function objects.
45 // </summary>
46 //
47 // <use visibility=local>
48 //
49 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tCombiFunction" demos="">
50 // </reviewed>
51 //
52 // <prerequisite>
53 // <li> <linkto class="CombiFunction">CombiFunction</linkto> class
54 // </prerequisite>
55 //
56 // <synopsis>
57 // Given N function objects, the class describes a linear combination of the
58 // form:
59 // <srcblock>
60 // f(x) = a(0)*f(0)(x) + a(1)*f(1)(x) + ... + a(N-1)*f(N-1)(x)
61 // </srcblock>
62 // where a = {a(n)} are parameters. If the combi function is used in
63 // a functional fitting process (see
64 // <linkto class=LinearFit>LinearFit</linkto>) these parameters canm be
65 // solved for. In all aspects they behave as
66 // <linkto class=FunctionParam>FunctionParam</linkto> values.
67 //
68 // Member functions are added with the <src>addFunction()</src> method.
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 // CombiParam<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 if dimensions of functions added different
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 
111 template <class T> class CombiParam : public Function<T>
112 {
113 public:
114  //# Constructors
115  // The default constructor -- no functions, no parameters, nothing, the
116  // function operator returns a 0.
117  CombiParam();
118  // Make this object a (deep) copy of other.
119  // <group>
120  CombiParam(const CombiParam<T> &other);
121  CombiParam(const CombiParam<T> &other, Bool) :
122  Function<T>(other), ndim_p(other.ndim_p),
124  for (uInt i=0; i<functionPtr_p.nelements(); ++i) {
125  functionPtr_p[i] = (*(other.functionPtr_p[i])).clone();
126  }
127  }
128  template <class W>
129  CombiParam(const CombiParam<W> &other) :
130  Function<T>(other), ndim_p(other.ndim()),
131  functionPtr_p(other.nFunctions()) {
132  for (uInt i=0; i<nFunctions(); ++i) {
133  functionPtr_p[i] = other.function(i).cloneAD();
134  }
135  }
136  template <class W>
137  CombiParam(const CombiParam<W> &other, Bool) :
138  Function<T>(other), ndim_p(other.ndim()),
139  functionPtr_p(other.nFunctions()) {
140  for (uInt i=0; i<nFunctions(); ++i) {
141  functionPtr_p[i] = other.function(i).cloneNonAD();
142  }
143  }
144  // </group>
145  // Make this object a (deep) copy of other.
146  CombiParam<T> &operator=(const CombiParam<T> &other);
147  // Destructor
148  virtual ~CombiParam();
149 
150  //# Operators
151 
152  //# Member functions
153  // Give name of function
154  virtual const String &name() const { static String x("combi");
155  return x; }
156 
157  // Add a function. All functions must have the same <src>ndim()</src>
158  // as the first one. Returns the (zero relative) number (<src>i</src>)
159  // of the function just added.
160  // The default initial parameter value (<src>a(i)</src>) is
161  // initialized to 1. The parameter mask is set <src>True</src>.
162  uInt addFunction(const Function<T> &newFunction);
163 
164  // Return the total number of functions. The number is equal to the
165  // number of functions that have been added.
166  uInt nFunctions() const { return nparameters(); }
167 
168  // Return a reference to a specific Function in the combination.
169  // <group>
170  const Function<T> &function(uInt which) const {
171  DebugAssert(nFunctions() > which, AipsError);
172  return *(functionPtr_p[which]); }
173  const Function<T> &function(uInt which) {
174  DebugAssert(nFunctions() > which, AipsError);
175  return *(functionPtr_p[which]); }
176  // </group>
177 
178  // Returns the dimension of functions in the linear combination
179  virtual uInt ndim() const { return ndim_p; }
180 
181 protected:
182  //# Data
183  // Number of dimensions of underlying functions
185 
186  // Pointer to each added function
188 
189  //# Make members of parent classes known.
190 public:
192 };
193 
194 
195 } //# NAMESPACE CASACORE - END
196 
197 #ifndef CASACORE_NO_AUTO_TEMPLATES
198 #include <casacore/scimath/Functionals/CombiParam.tcc>
199 #endif //# CASACORE_NO_AUTO_TEMPLATES
200 #endif
uInt nparameters() const
Returns the number of parameters.
Definition: Function.h:238
PtrBlock< Function< T > * > functionPtr_p
Pointer to each added function.
Definition: CombiParam.h:187
uInt ndim_p
Number of dimensions of underlying functions.
Definition: CombiParam.h:184
CombiParam(const CombiParam< T > &other, Bool)
Definition: CombiParam.h:121
CombiParam(const CombiParam< W > &other, Bool)
Definition: CombiParam.h:137
Parameters for a linear combination of function objects.
Definition: CombiParam.h:111
const Function< T > & function(uInt which) const
Return a reference to a specific Function in the combination.
Definition: CombiParam.h:170
CombiParam< T > & operator=(const CombiParam< T > &other)
Make this object a (deep) copy of other.
CombiParam()
The default constructor – no functions, no parameters, nothing, the function operator returns a 0...
virtual ~CombiParam()
Destructor.
Numerical functional interface class.
uInt addFunction(const Function< T > &newFunction)
Add a function.
LatticeExprNode nelements(const LatticeExprNode &expr)
1-argument function to get the number of elements in a lattice.
#define DebugAssert(expr, exception)
Definition: Assert.h:185
virtual const String & name() const
Give name of function.
Definition: CombiParam.h:154
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
CombiParam(const CombiParam< W > &other)
Definition: CombiParam.h:129
A drop-in replacement for Block&lt;T*&gt;.
Definition: WProjectFT.h:54
Base class for all Casacore library errors.
Definition: Error.h:134
virtual uInt ndim() const
Returns the dimension of functions in the linear combination.
Definition: CombiParam.h:179
String: the storage and methods of handling collections of characters.
Definition: String.h:223
unsigned int uInt
Definition: aipstype.h:51
uInt nFunctions() const
Return the total number of functions.
Definition: CombiParam.h:166
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42