casacore
Loading...
Searching...
No Matches
Gaussian1D.h
Go to the documentation of this file.
1// # Gaussian1D.h: A one-dimensional Gaussian class
2// # Copyright (C) 1995,1996,1997,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_GAUSSIAN1D_H
27#define SCIMATH_GAUSSIAN1D_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/Gaussian1DParam.h>
32#include <casacore/scimath/Functionals/Function1D.h>
33#include <casacore/scimath/Mathematics/AutoDiff.h>
34#include <casacore/scimath/Mathematics/AutoDiffMath.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// # Forward declarations
39
40// <summary> A one dimensional Gaussian class.</summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="tcornwel" date="1996/02/22" tests="tGaussian1D"
45// demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class="Gaussian1DParam">Gaussian1DParam</linkto>
50// <li> <linkto class="Function">Function</linkto>
51// </prerequisite>
52
53// <etymology>
54// A Gaussian1D functional is designed exclusively for calculating a
55// Gaussian (or Normal) distribution in one dimension. Other classes exist
56// for calculating these functions in two
57// (<linkto class=Gaussian2D>Gaussian2D</linkto>) and N
58// (<linkto class=GaussianND>GaussianND</linkto>) dimensions.
59// </etymology>
60
61// <synopsis>
62// A <src>Gaussian1D</src> is described by a height, center, and width. Its
63// fundamental operation is evaluating itself at some <src>x</src>.
64// The parameters (height, center and width) may be changed at run time.
65//
66// The width of the Gaussian (for the constructors or the <src>setWidth
67// </src> function) is always specified in terms of the full width at half
68// maximum (FWHM). It is always positive and attempts to set a non-positive
69// width will throw an assertion when in debug mode.
70//
71// The peak height of the Gaussian can be specified at construction time or
72// by using the <src> setHeight </src> function. Alternatively the <src>
73// setFlux </src> function can be used to implicitly set the peak height by
74// specifying the integrated area under the Gaussian. The height (or flux)
75// can be positive, negative or zero, as this class makes no assumptions on
76// what quantity the height represents.
77//
78// <note role=tip> Changing the width of the Gaussian will not affect
79// its peak height but will change its flux. So you should always set the
80// width before setting the flux. </note>
81//
82// The parameter interface (see
83// <linkto class="Gaussian1DParam">Gaussian1DParam</linkto> class),
84// is used to provide an interface to the
85// <linkto module="Fitting">Fitting</linkto> classes.
86//
87// There are 3 parameters that are used to describe the Gaussian:
88// <ol>
89// <li> The height of the Gaussian. This is identical to the value
90// returned using the <src>height()</src> member function.
91// <li> The center of the Gaussian in the x direction. This is identical to
92// the value returned using the <src>center()</src> member function.
93// <li> The width (FWHM) of the Gaussian. To aid convergence of
94// the non-linear fitting routines this parameter is allowed to be
95// negative. This does not affect the shape of the Gaussian as the
96// square of the width is used when evaluating the function.
97// </ol>
98//
99// An enumeration for the <src>HEIGHT</src>, <src>WIDTH</src> and
100// <src>CENTER</src> parameter index is provided, enabling the setting
101// and reading of parameters with the <src>[]</src> operator. The
102// <src>mask()</src> methods can be used to check and set the parameter masks.
103//
104// </synopsis>
105
106// <example>
107// <srcblock>
108// Gaussian<Double> gf(5.0, 25.0, 7);
109// gf(25); // = 5.0
110// gf[HEIGHT](1.0);
111// gf.setWidth(2.0);
112// gf[CENTER](0.0);
113// gf(1); // = 0.5*height = 0.5
114// </srcblock>
115// </example>
116
117// <templating arg=T>
118// <li> T should have standard numerical operators and exp() function. Current
119// implementation only tested for real types.
120// <li> To obtain derivatives, the derivatives should be defined.
121// </templating>
122
123// <thrown>
124// <li> Assertion in debug mode if attempt is made to set a negative width
125// <li> AipsError if incorrect parameter number specified.
126// <li> Assertion in debug mode if operator(Vector<>) with empty Vector
127// </thrown>
128
129// <todo asof="2001/08/19">
130// <li> Gaussians that know about their DFT's could be required eventually.
131// </todo>
132
133template <class T>
134class Gaussian1D : public Gaussian1DParam<T> {
135 public:
136 // # Enumerations
137
138 // # Constructors
139 // Constructs the one dimensional Gaussians. Defaults:
140 // height=1, center=0, width(FWHM)=1.
141 // <note role=warning> Could not use default arguments
142 // that worked both with gcc and IRIX </note>
143 // <group>
145 explicit Gaussian1D(const T &height) : Gaussian1DParam<T>(height) {}
146 Gaussian1D(const T &height, const T &center) : Gaussian1DParam<T>(height, center) {}
147 Gaussian1D(const T &height, const T &center, const T &width)
149 // </group>
150
151 // Copy constructor (deep copy)
152 // <group>
153 Gaussian1D(const Gaussian1D<T> &other) : Gaussian1DParam<T>(other) {}
154 template <class W>
155 Gaussian1D(const Gaussian1D<W> &other) : Gaussian1DParam<T>(other) {}
156 // </group>
157
158 // Copy assignment (deep copy)
161 return *this;
162 }
163
164 // Destructor
165 virtual ~Gaussian1D() {}
166
167 // # Operators
168 // Evaluate the Gaussian at <src>x</src>.
169 // <group>
170 virtual T eval(typename Function1D<T>::FunctionArg x) const;
171 // </group>
172
173 // # Member functions
174 // Return a copy of this object from the heap. The caller is responsible
175 // for deleting this pointer.
176 // <group>
177 virtual Function<T> *clone() const { return new Gaussian1D<T>(*this); }
184 // </group>
185
186 // # Make members of parent classes known.
187 protected:
189
190 public:
193 using Gaussian1DParam<T>::WIDTH;
195};
196
197#define Gaussian1D_PS Gaussian1D
198
199// <summary> Partial specialization of Gaussian1D for <src>AutoDiff</src>
200// </summary>
201
202// <synopsis>
203// <note role=warning> The name <src>Gaussian1D_PS</src> is only for cxx2html
204// documentation problems. Use <src>Gaussian1D</src> in your code.</note>
205// </synopsis>
206
207template <class T>
208class Gaussian1D_PS<AutoDiff<T>> : public Gaussian1DParam<AutoDiff<T>> {
209 public:
210 // # Constructors
211 // Constructs one dimensional Gaussians.
212 // <group>
215 Gaussian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center)
217 Gaussian1D_PS(const AutoDiff<T> &height, const AutoDiff<T> &center, const AutoDiff<T> &width)
218 : Gaussian1DParam<AutoDiff<T>>(height, center, width) {}
219 // </group>
220
221 // Copy constructor (deep copy)
222 // <group>
223 Gaussian1D_PS(const Gaussian1D_PS &other) : Gaussian1DParam<AutoDiff<T>>(other) {}
224 template <class W>
225 Gaussian1D_PS(const Gaussian1D_PS<W> &other) : Gaussian1DParam<AutoDiff<T>>(other) {}
226 // </group>
227
228 // Copy assignment (deep copy)
230 Gaussian1DParam<AutoDiff<T>>::operator=(other);
231 return *this;
232 }
233
234 // Destructor
235 virtual ~Gaussian1D_PS() {}
236
237 // # Operators
238 // Evaluate the Gaussian and its derivatives at <src>x</src>.
239 // <group>
240 virtual AutoDiff<T> eval(typename Function<AutoDiff<T>>::FunctionArg x) const;
241 // </group>
242
243 // # Member functions
244 // Return a copy of this object from the heap. The caller is responsible
245 // for deleting this pointer.
246 // <group>
247 virtual Function<AutoDiff<T>> *clone() const { return new Gaussian1D<AutoDiff<T>>(*this); }
248 virtual Function<typename FunctionTraits<AutoDiff<T>>::DiffType> *cloneAD() const {
249 return new Gaussian1D<typename FunctionTraits<AutoDiff<T>>::DiffType>(*this);
251 virtual Function<typename FunctionTraits<AutoDiff<T>>::BaseType> *cloneNonAD() const {
252 return new Gaussian1D<typename FunctionTraits<AutoDiff<T>>::BaseType>(*this);
253 }
254 // </group>
255
256 // # Make members of parent classes known.
257 protected:
258 using Gaussian1DParam<AutoDiff<T>>::param_p;
259
260 public:
261 using Gaussian1DParam<AutoDiff<T>>::HEIGHT;
262 using Gaussian1DParam<AutoDiff<T>>::CENTER;
263 using Gaussian1DParam<AutoDiff<T>>::WIDTH;
264 using Gaussian1DParam<AutoDiff<T>>::fwhm2int;
265};
266
267#undef Gaussian1D_PS
268
269} // namespace casacore
270
271#ifndef CASACORE_NO_AUTO_TEMPLATES
272#include <casacore/scimath/Functionals/Gaussian1D.tcc>
273#include <casacore/scimath/Functionals/Gaussian1D2.tcc>
274#endif // # CASACORE_NO_AUTO_TEMPLATES
275#endif
#define Gaussian1D_PS
Definition Gaussian1D.h:197
const T * FunctionArg
Definition Function1D.h:76
FunctionParam< T > param_p
Definition Function.h:337
T center() const
Get or set the center ordinate of the Gaussian.
Gaussian1DParam< T > & operator=(const Gaussian1DParam< T > &other)
Copy assignment (deep copy).
Gaussian1DParam()
Constructs the one dimensional Gaussians.
T fwhm2int
Constant to scale halfwidth at 1/e to FWHM.
T width() const
Get or set the FWHM of the Gaussian.
T height() const
Get or set the peak height of the Gaussian.
Gaussian1D_PS(const AutoDiff< T > &height, const AutoDiff< T > &center, const AutoDiff< T > &width)
Definition Gaussian1D.h:216
virtual Function< typename FunctionTraits< AutoDiff< T > >::BaseType > * cloneNonAD() const
Definition Gaussian1D.h:250
virtual Function< AutoDiff< T > > * clone() const
Return a copy of this object from the heap.
Definition Gaussian1D.h:246
Gaussian1D_PS()
Constructs one dimensional Gaussians.
Definition Gaussian1D.h:212
virtual AutoDiff< T > eval(typename Function< AutoDiff< T > >::FunctionArg x) const
Evaluate the Gaussian and its derivatives at x.
Gaussian1D_PS(const AutoDiff< T > &height, const AutoDiff< T > &center)
Definition Gaussian1D.h:214
Gaussian1D_PS< AutoDiff< T > > & operator=(const Gaussian1D_PS< AutoDiff< T > > &other)
Copy assignment (deep copy).
Definition Gaussian1D.h:228
Gaussian1D_PS(const AutoDiff< T > &height)
Definition Gaussian1D.h:213
Gaussian1D_PS(const Gaussian1D_PS< W > &other)
Definition Gaussian1D.h:224
Gaussian1D_PS(const Gaussian1D_PS &other)
Copy constructor (deep copy).
Definition Gaussian1D.h:222
virtual Function< typename FunctionTraits< AutoDiff< T > >::DiffType > * cloneAD() const
Definition Gaussian1D.h:247
virtual T eval(typename Function1D< T >::FunctionArg x) const
Evaluate the Gaussian at x.
Gaussian1D()
Constructs the one dimensional Gaussians.
Definition Gaussian1D.h:144
virtual ~Gaussian1D()
Destructor.
Definition Gaussian1D.h:165
Gaussian1D< T > & operator=(const Gaussian1D< T > &other)
Copy assignment (deep copy).
Definition Gaussian1D.h:159
Gaussian1D(const Gaussian1D< T > &other)
Copy constructor (deep copy).
Definition Gaussian1D.h:153
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition Gaussian1D.h:177
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Gaussian1D.h:178
Gaussian1D(const T &height, const T &center, const T &width)
Definition Gaussian1D.h:147
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Gaussian1D.h:181
Gaussian1D(const T &height)
Definition Gaussian1D.h:145
Gaussian1D(const T &height, const T &center)
Definition Gaussian1D.h:146
Gaussian1D(const Gaussian1D< W > &other)
Definition Gaussian1D.h:155
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition Polynomial.h:126
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition Polynomial.h:129