casacore
Loading...
Searching...
No Matches
SPolynomialParam.h
Go to the documentation of this file.
1// # SPolynomialParam.h: Parameter handling for scaled 1-D polynomials
2// # Copyright (C) 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_SPOLYNOMIALPARAM_H
27#define SCIMATH_SPOLYNOMIALPARAM_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Functionals/Function.h>
32#include <casacore/casa/BasicSL/String.h>
33#include <casacore/casa/Utilities/Assert.h>
34#include <casacore/casa/Arrays/ArrayFwd.h>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// <summary> Parameter handling for scaled 1-D polynomials
39// </summary>
40
41// <reviewed reviewer="" date="" tests="tSPolynomial"
42// demos="">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class="FunctionParam">FunctionParam</linkto> class
47// <li> <linkto class=Function>Function</linkto>
48// </prerequisite>
49
50// <etymology>
51// A 1-dimensional Scaled Polynomial's parameters.
52// </etymology>
53//
54// <synopsis>
55// A <src>SPolynomial</src> is described by a set of coefficients;
56// its fundamental operation is evaluating itself at some "x".
57// The number of coefficients is the order of the polynomial plus one,
58// plus three, describing a height, center and width. These three parameters
59// are the first three, and have default values of 1, 0, 1.
60//
61// Since the <src>SPolynomial</src> is a <src>Function</src>, the derivatives
62// can be obtained as well.
63//
64// The parameter interface (see
65// <linkto class="FunctionParam">FunctionParam</linkto> class),
66// is used to provide an interface to the
67// <linkto module="Fitting">Fitting</linkto> classes.
68//
69// This class is in general used implicitly by the <src>SPolynomial</src>
70// class only.
71// </synopsis>
72//
73// <example>
74// <srcblock>
75// SPolynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default
76// pf.setCoefficient(1, 1.0);
77// pf[5] = 2.0;
78// pf.setCoefficient(3, 3.0); // 3x^3 + 2x^2 + x
79// pf(2); // == 34
80// </srcblock>
81// </example>
82
83// <templating arg=T>
84// <li> T should have standard numerical operators. Current
85// implementation only tested for real types (and their AutoDiffs).
86// </templating>
87
88// <thrown>
89// <li> Assertion in debug mode if attempt is made to address incorrect
90// coefficients
91// </thrown>
92
93// <todo asof="2002/05/20">
94// <li> Nothing I know of
95// </todo>
96
97template <class T>
98class SPolynomialParam : public Function<T> {
99 public:
100 // # Constructors
101 // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
103
104 // Makes a polynomial of the given order, with all coeficcients set to
105 // zero.
107
108 // Make this a copy of other (deep copy).
109 // <group>
111 template <class W>
112 SPolynomialParam(const SPolynomialParam<W> &other) : Function<T>(other) {}
114 // </group>
115
116 // Destructor
118
119 // # Operators
120 // Comparisons.
121 // SPolynomials are equal if they are of the same order
122 // <group>
123 Bool operator==(const SPolynomialParam<T> &other) const { return (param_p == other.param_p); }
124 Bool operator!=(const SPolynomialParam<T> &other) const { return (param_p != other.param_p); }
125 // </group>
126
127 // # Member functions
128 // Give name of function
129 virtual const String &name() const {
130 static String x("spolynomial");
131 return x;
132 }
133
134 // What is the order of the polynomial, i.e. maximum exponent of "x".
135 uInt order() const { return param_p.nelements() - 4; }
136
137 // What is the <em>which</em>'th coefficient of the polynomial. For an nth
138 // degree polynomial, <em>which</em> varies between zero and n.
139 T coefficient(uInt which) const {
140 DebugAssert(which <= order(), AipsError);
141 return param_p[which + 3];
142 }
143
144 // Return all the coefficients as a vector.
146
147 // Set the <em>which</em>'th coefficient to <em>value</em>.
148 void setCoefficient(uInt which, const T value) {
149 DebugAssert(which <= order(), AipsError);
150 param_p[which + 3] = value;
151 }
152
153 // Set all the coefficients at once, throw away all existing coefficients.
155
156 // Returns the dimension of function
157 virtual uInt ndim() const { return 1; }
158
159 // # Make members of parent classes known.
160 protected:
161 using Function<T>::param_p;
162
163 public:
164 using Function<T>::nparameters;
165 using Function<T>::mask;
166};
167
168} // namespace casacore
169
170#ifndef CASACORE_NO_AUTO_TEMPLATES
171#include <casacore/scimath/Functionals/SPolynomialParam.tcc>
172#endif // # CASACORE_NO_AUTO_TEMPLATES
173#endif
#define DebugAssert(expr, exception)
Definition Assert.h:161
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:337
Function()
Constructors.
Definition Function.h:209
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:226
SPolynomialParam< T > & operator=(const SPolynomialParam< T > &other)
T coefficient(uInt which) const
What is the which'th coefficient of the polynomial.
virtual uInt ndim() const
Returns the dimension of function.
SPolynomialParam(uInt order)
Makes a polynomial of the given order, with all coeficcients set to zero.
~SPolynomialParam()
Destructor.
void setCoefficient(uInt which, const T value)
Set the which'th coefficient to value.
Bool operator==(const SPolynomialParam< T > &other) const
Comparisons.
SPolynomialParam(const SPolynomialParam< T > &other)
Make this a copy of other (deep copy).
Bool operator!=(const SPolynomialParam< T > &other) const
uInt order() const
What is the order of the polynomial, i.e.
SPolynomialParam()
Constructs a zero'th order polynomial, with a coeficcient of 0.0.
SPolynomialParam(const SPolynomialParam< W > &other)
Vector< T > coefficients() const
Return all the coefficients as a vector.
void setCoefficients(const Vector< T > &coefficients)
Set all the coefficients at once, throw away all existing coefficients.
virtual const String & name() const
Give name of function.
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360