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