casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OddPolynomialParam.h
Go to the documentation of this file.
1 //# OddPolynomialParam.h: Parameter handling for odd 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_ODDPOLYNOMIALPARAM_H
29 #define SCIMATH_ODDPOLYNOMIALPARAM_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 odd polynomials
43 // </summary>
44 
45 // <reviewed reviewer="tcornwel" date="1996/02/22" tests="tSpecialPolynomial"
46 // demos="">
47 // </reviewed>
48 
49 // <prerequisite>
50 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class
51 // <li> <linkto class=Function1D>Function1D</linkto>
52 // </prerequisite>
53 
54 // <etymology>
55 // A 1-dimensional OddPolynomial's parameters.
56 // </etymology>
57 //
58 // <synopsis>
59 // An <src>OddPolynomial</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 divided
62 // by two, plus one.
63 //
64 // Since the <src>OddPolynomial</src> is a <src>Function</src>, the derivatives
65 // can be obtained as well.
66 //
67 // The parameter interface (see
68 // <linkto class="FunctionParam">FunctionParam</linkto> class),
69 // is used to provide an interface to the
70 // <linkto module="Fitting">Fitting</linkto> classes.
71 //
72 // This class is in general used implicitly by the <src>OddPolynomial</src>
73 // class only.
74 // </synopsis>
75 //
76 // <example>
77 // <srcblock>
78 // OddPolynomial<Float> pf(3); // Third order polynomial - coeffs 0 by default
79 // pf.setCoefficient(0, 1.0);
80 // pf[1] = 2.0; // 2x^3 + 1x^1
81 // pf(2); // == 18
82 // </srcblock>
83 // </example>
84 
85 // <templating arg=T>
86 // <li> T should have standard numerical operators. Current
87 // implementation only tested for real types (and their AutoDiffs).
88 // </templating>
89 
90 // <thrown>
91 // <li> Assertion in debug mode if attempt is made to address incorrect
92 // coefficients
93 // </thrown>
94 
95 // <todo asof="2002/02/26">
96 // <li> Nothing I know off
97 // </todo>
98 
99 template<class T> class OddPolynomialParam: public Function1D<T>
100 {
101 public:
102  //# Constructors
103  // Constructs a first order polynomial, with a coeficcient of 0.0.
105 
106  // Makes a polynomial of the given order, with all coeficcients set to
107  // zero.
108  explicit OddPolynomialParam(uInt order);
109 
110  // Make this a copy of other (deep copy).
111  // <group>
113  template <class W>
115  Function1D<T>(other) {}
117  // </group>
118 
119  // Destructor
121 
122  //# Operators
123  // Comparisons.
124  // OddPolynomials are equal if they are the same order
125  // <group>
126  Bool operator==(const OddPolynomialParam<T> &other) const {
127  return (param_p == other.param_p); }
128  Bool operator!=(const OddPolynomialParam<T> &other) const {
129  return (param_p != other.param_p); }
130  // </group>
131 
132  //# Member functions
133  // Give name of function
134  virtual const String &name() const { static String x("oddpolynomial");
135  return x; }
136 
137  // What is the order of the polynomial, i.e. maximum exponent of "x".
138  uInt order() const { return 2*param_p.nelements() - 1; }
139 
140  // What is the <em>which</em>'th coefficient of the polynomial. For an nth
141  // degree polynomial, <em>which</em> varies between zero and n/2.
142  T coefficient(uInt which) const {
143  DebugAssert(which<=order(), AipsError); return param_p[which]; }
144 
145  // Return all the coefficients as a vector.
146  const Vector<T> &coefficients() const;
147 
148  // Set the <em>which</em>'th coefficient to <em>value</em>.
149  void setCoefficient(uInt which, const T value) {
150  DebugAssert(which<=order(), AipsError); param_p[which] = value; }
151 
152  // Set all the coefficients at once, throw away all existing coefficients.
154 
155  //# Make members of parent classes known.
156 protected:
158 public:
160 };
161 
162 
163 } //# NAMESPACE CASACORE - END
164 
165 #ifndef CASACORE_NO_AUTO_TEMPLATES
166 #include <casacore/scimath/Functionals/OddPolynomialParam.tcc>
167 #endif //# CASACORE_NO_AUTO_TEMPLATES
168 #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
void setCoefficients(const Vector< T > &coefficients)
Set all the coefficients at once, throw away all existing coefficients.
OddPolynomialParam()
Constructs a first order polynomial, with a coeficcient of 0.0.
OddPolynomialParam< T > & operator=(const OddPolynomialParam< T > &other)
void setCoefficient(uInt which, const T value)
Set the which&#39;th coefficient to value.
~OddPolynomialParam()
Destructor.
T coefficient(uInt which) const
What is the which&#39;th coefficient of the polynomial.
#define DebugAssert(expr, exception)
Definition: Assert.h:185
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool operator==(const OddPolynomialParam< T > &other) const
Comparisons.
uInt order() const
What is the order of the polynomial, i.e.
const Vector< T > & coefficients() const
Return all the coefficients as a vector.
OddPolynomialParam(const OddPolynomialParam< W > &other)
Numerical functional interface class for 1 dimension.
Definition: Function1D.h:75
virtual const String & name() const
Give name of function.
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
Bool operator!=(const OddPolynomialParam< T > &other) const
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
Parameter handling for odd polynomials.
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