casacore
Loading...
Searching...
No Matches
FunctionParam.h
Go to the documentation of this file.
1//# FunctionParam.h: Container of function parameters with masking flags
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_FUNCTIONPARAM_H
27#define SCIMATH_FUNCTIONPARAM_H
28
29//# Include files
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/scimath/Functionals/FunctionTraits.h>
33
34//# Forward declarations
35#include <casacore/casa/iosfwd.h>
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39// <summary>Container of function parameters with masking flags
40// </summary>
41//
42// <use visibility=export>
43//
44// <reviewed reviewer="tcornwel" date="1996/02/22" tests="tGaussian2D"
45// demos="">
46// </reviewed>
47//
48// <synopsis>
49// <src>FunctionParam</src> is used to provide an interface to an entity which
50// has parameters that can be flagged.
51// This is useful, for example, in implementing parameter
52// fitting which operates on generic function objects.
53//
54// Each parameter can be masked. The mask can, e.g., be used to indicate to a
55// generic least-squares fitting routine to only adjust parameters with
56// a <em>True</em> mask (the default). For that reason methods that only
57// handle <em>True</em> data items have names with <em>Adjust</em> in
58// the names. In general the user should not be concerned with these
59// methods, but should only manipulate the parameter <src>flags</src> and
60// <src>values</src>.
61//
62// </synopsis>
63//
64// <example>
65// See the <linkto class=Function>Function</linkto> class for a usage
66// interface.
67// </example>
68//
69// <motivation>
70// Generically manipulatable adjustable parameters are important for fitting.
71// </motivation>
72//
73// <templating arg=T>
74// <li> <src>T</src> must have a default constructor, assignment operator,
75// and copy constructor (for the Vector interface).
76// <li> all standard mathematical should be applicable if the
77// parameter interface is used for the calculation of
78// <src>Functions</src>.
79// </templating>
80//
81// <todo asof="2001/08/28">
82// <li> Nothing I know of
83// </todo>
84
85template<class T> class FunctionParam {
86 public:
87 //# Constructors
88 // Construct a default FunctionParam with 0 parameters
90 // Construct a FunctionParam with <src>n</src> parameters with zero value and
91 // all masks <em>True</em>
92 explicit FunctionParam(const uInt n);
93 // Construct a FunctionParam from the given vector, with all masks
94 // <em>True</em>
95 explicit FunctionParam(const Vector<T> &in);
96 // Copy constructor (deep copy)
98 // Copy from different type (deep copy)
99 template <class W>
101 : npar_p(other.getParameters().nelements()),
103 maskedPtr_p(0) {
104 for (uInt i=0; i<npar_p; ++i) {
108 npar_p, i);
109 }
110 mask_p = other.getParamMasks();
111 }
112
113 // Destructor
114 virtual ~FunctionParam();
115
116 //# Operators
117 // Copy assignment (deep copy)
119 // Manipulate the nth parameter (0-based) with no index check
120 // <group>
121 T &operator[](const uInt n) { return param_p[n]; }
122 const T &operator[](const uInt n) const { return param_p[n]; }
123 // </group>
124 // Compare two parameter sets for equal size, values and masks.
125 // <group>
126 Bool operator==(const FunctionParam<T> &other) const;
127 Bool operator!=(const FunctionParam<T> &other) const;
128 // </group>
129
130 //# Member functions
131 // Return the number of parameters
132 uInt nelements() const { return param_p.nelements(); }
133 // Manipulate the nth parameter (0-based) with no index check
134 // <group>
135 T &parameter(const uInt n) { return param_p[n]; }
136 const T &parameter(const uInt n) const{ return param_p[n]; }
137 // </group>
138
139 // Manipulate the mask associated with the nth parameter
140 // (e.g. to indicate whether the parameter is adjustable or nonadjustable).
141 // Note no index check.
142 // <group>
143 Bool &mask(const uInt n);
144 const Bool &mask(const uInt n) const { return mask_p[n]; }
145 // </group>
146
147 // Get all parameters at once. Returns zero length
148 // Vector if there are no parameters.
149 const Vector<T> &getParameters() const { return param_p; }
150
151 // Set all the parameters at once. Only the minimum of the input number and
152 // the object number of parameters will be set.
153 void setParameters(const Vector<T> &params);
154
155 // Get all parameter masks at once. Returns zero length
156 // Vector if there are no parameters.
157 const Vector<Bool> &getParamMasks() const { return mask_p; }
158
159 // Set all parameter masks at once. Only the minimum of the input number and
160 // the object number of parameters will be set.
161 void setParamMasks(const Vector<Bool> &masks);
162
163 // Operations on the masked parameters only. For possible re-use the
164 // results are cached.
165 // <group>
166 // Number of masked (<src>=True</src>) parameters
168 // All masked parameters only
169 // <group>
172 // </group>
173 // </group>
174
175 // Output the parameters
176 ostream &print(ostream &os) const;
177
178 private:
179 //# Data
180 // Number of parameters
182 // Parameters
184 // Masks
186 // Cached masked data
188
189 //# Methods
190 // Create a cached version of the masked parameter list
191 void createMaskedPtr() const;
192 // Clear the masked parameter list
193 void clearMaskedPtr() const;
194
195};
196
197//# Global functions
198// <summary> Global functions </summary>
199// <group name=Output>
200// Output declaration
201template<class T>
202ostream &operator<<(ostream &os, const FunctionParam<T> &par);
203// </group>
205//# Inlines
206template<class T>
207inline ostream &operator<<(ostream &os, const FunctionParam<T> &par) {
208 return par.print(os); }
209
210
211} //# NAMESPACE CASACORE - END
212
213#ifndef CASACORE_NO_AUTO_TEMPLATES
214#include <casacore/scimath/Functionals/FunctionParam.tcc>
215#endif //# CASACORE_NO_AUTO_TEMPLATES
216#endif
217
FunctionParam(const Vector< T > &in)
Construct a FunctionParam from the given vector, with all masks True
FunctionParam()
Construct a default FunctionParam with 0 parameters.
Bool operator!=(const FunctionParam< T > &other) const
virtual ~FunctionParam()
Destructor.
const Bool & mask(const uInt n) const
void setParameters(const Vector< T > &params)
Set all the parameters at once.
FunctionParam(const uInt n)
Construct a FunctionParam with n parameters with zero value and all masks True
uInt nelements() const
Return the number of parameters.
Vector< Bool > mask_p
Masks.
uInt nMaskedParameters() const
Operations on the masked parameters only.
T & parameter(const uInt n)
Manipulate the nth parameter (0-based) with no index check.
Bool & mask(const uInt n)
Manipulate the mask associated with the nth parameter (e.g.
Bool operator==(const FunctionParam< T > &other) const
Compare two parameter sets for equal size, values and masks.
const Vector< Bool > & getParamMasks() const
Get all parameter masks at once.
void clearMaskedPtr() const
Clear the masked parameter list.
void setParamMasks(const Vector< Bool > &masks)
Set all parameter masks at once.
FunctionParam & operator=(const FunctionParam< T > &other)
Copy assignment (deep copy)
FunctionParam(const FunctionParam< W > &other)
Copy from different type (deep copy)
ostream & print(ostream &os) const
Output the parameters.
const T & parameter(const uInt n) const
void setMaskedParameters(Vector< T > &in)
const T & operator[](const uInt n) const
uInt npar_p
Number of parameters.
FunctionParam(const FunctionParam< T > &other)
Copy constructor (deep copy)
Vector< T > * maskedPtr_p
Cached masked data.
Vector< T > & getMaskedParameters() const
All masked parameters only.
T & operator[](const uInt n)
Manipulate the nth parameter (0-based) with no index check.
Vector< T > param_p
Parameters.
void createMaskedPtr() const
Create a cached version of the masked parameter list.
const Vector< T > & getParameters() const
Get all parameters at once.
static void setValue(T &out, const T &val, const uInt, const uInt)
Set a value (and possible derivative)
this file contains all the compiler specific defines
Definition mainpage.dox:28
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
ostream & operator<<(ostream &os, const FunctionParam< T > &par)
Output declaration.