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