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>
87 public:
88 // # Constructors
89 // Construct a default FunctionParam with 0 parameters
91 // Construct a FunctionParam with <src>n</src> parameters with zero value and
92 // all masks <em>True</em>
93 explicit FunctionParam(const uInt n);
94 // Construct a FunctionParam from the given vector, with all masks
95 // <em>True</em>
96 explicit FunctionParam(const Vector<T> &in);
97 // Copy constructor (deep copy)
99 // Copy from different type (deep copy)
100 template <class W>
103 for (uInt i = 0; i < npar_p; ++i) {
105 npar_p, i);
106 }
107 mask_p = other.getParamMasks();
108 }
109
110 // Destructor
111 virtual ~FunctionParam();
112
113 // # Operators
114 // Copy assignment (deep copy)
116 // Manipulate the nth parameter (0-based) with no index check
117 // <group>
118 T &operator[](const uInt n) { return param_p[n]; }
119 const T &operator[](const uInt n) const { return param_p[n]; }
120 // </group>
121 // Compare two parameter sets for equal size, values and masks.
122 // <group>
123 Bool operator==(const FunctionParam<T> &other) const;
124 Bool operator!=(const FunctionParam<T> &other) const;
125 // </group>
126
127 // # Member functions
128 // Return the number of parameters
129 uInt nelements() const { return param_p.nelements(); }
130 // Manipulate the nth parameter (0-based) with no index check
131 // <group>
132 T &parameter(const uInt n) { return param_p[n]; }
133 const T &parameter(const uInt n) const { return param_p[n]; }
134 // </group>
135
136 // Manipulate the mask associated with the nth parameter
137 // (e.g. to indicate whether the parameter is adjustable or nonadjustable).
138 // Note no index check.
139 // <group>
140 Bool &mask(const uInt n);
141 const Bool &mask(const uInt n) const { return mask_p[n]; }
142 // </group>
143
144 // Get all parameters at once. Returns zero length
145 // Vector if there are no parameters.
146 const Vector<T> &getParameters() const { return param_p; }
147
148 // Set all the parameters at once. Only the minimum of the input number and
149 // the object number of parameters will be set.
150 void setParameters(const Vector<T> &params);
151
152 // Get all parameter masks at once. Returns zero length
153 // Vector if there are no parameters.
154 const Vector<Bool> &getParamMasks() const { return mask_p; }
155
156 // Set all parameter masks at once. Only the minimum of the input number and
157 // the object number of parameters will be set.
158 void setParamMasks(const Vector<Bool> &masks);
159
160 // Operations on the masked parameters only. For possible re-use the
161 // results are cached.
162 // <group>
163 // Number of masked (<src>=True</src>) parameters
165 // All masked parameters only
166 // <group>
169 // </group>
170 // </group>
171
172 // Output the parameters
173 ostream &print(ostream &os) const;
174
175 private:
176 // # Data
177 // Number of parameters
179 // Parameters
181 // Masks
183 // Cached masked data
185
186 // # Methods
187 // Create a cached version of the masked parameter list
188 void createMaskedPtr() const;
189 // Clear the masked parameter list
190 void clearMaskedPtr() const;
191};
192
193// # Global functions
194// <summary> Global functions </summary>
195// <group name=Output>
196// Output declaration
197template <class T>
198ostream &operator<<(ostream &os, const FunctionParam<T> &par);
199// </group>
201// # Inlines
202template <class T>
203inline ostream &operator<<(ostream &os, const FunctionParam<T> &par) {
204 return par.print(os);
205}
206
207} // namespace casacore
208
209#ifndef CASACORE_NO_AUTO_TEMPLATES
210#include <casacore/scimath/Functionals/FunctionParam.tcc>
211#endif // # CASACORE_NO_AUTO_TEMPLATES
212#endif
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).
static const T & getValue(const T &in)
Get the value.
For temporary backward namespace compatibility, use casa as alias for casacore.
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.