casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SPolynomialParam.h
Go to the documentation of this file.
00001 //# SPolynomialParam.h: Parameter handling for scaled 1-D polynomials
00002 //# Copyright (C) 2002,2005
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: SPolynomialParam.h 21024 2011-03-01 11:46:18Z gervandiepen $
00027 
00028 #ifndef SCIMATH_SPOLYNOMIALPARAM_H
00029 #define SCIMATH_SPOLYNOMIALPARAM_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <scimath/Functionals/Function.h>
00034 #include <casa/BasicSL/String.h>
00035 #include <casa/Utilities/Assert.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward declarations
00040 template<class T> class Vector;
00041 
00042 // <summary>  Parameter handling for scaled 1-D polynomials
00043 // </summary>
00044 
00045 // <reviewed reviewer="" date="" tests="tSPolynomial"
00046 // demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class="FunctionParam">FunctionParam</linkto> class
00051 //   <li> <linkto class=Function>Function</linkto>
00052 // </prerequisite>
00053 
00054 // <etymology> 
00055 // A 1-dimensional Scaled Polynomial's parameters.
00056 // </etymology>
00057 //
00058 // <synopsis> 
00059 // A <src>SPolynomial</src> is described by a set of coefficients;
00060 // its fundamental operation is evaluating itself at some "x".
00061 // The number of coefficients is the order of the polynomial plus one,
00062 // plus three, describing a height, center and width. These three parameters
00063 // are the first three, and have default values of 1, 0, 1. 
00064 //
00065 // Since the <src>SPolynomial</src> is a <src>Function</src>, the derivatives
00066 // can be obtained as well. 
00067 //
00068 // The parameter interface (see 
00069 // <linkto class="FunctionParam">FunctionParam</linkto> class), 
00070 // is used to provide an interface to the
00071 // <linkto module="Fitting">Fitting</linkto> classes. 
00072 //
00073 // This class is in general used implicitly by the <src>SPolynomial</src>
00074 // class only.
00075 // </synopsis> 
00076 //
00077 // <example>
00078 // <srcblock>
00079 //  SPolynomial<Float> pf(3);  // Third order polynomial - coeffs 0 by default
00080 //  pf.setCoefficient(1, 1.0);
00081 //  pf[5] = 2.0;
00082 //  pf.setCoefficient(3, 3.0);  // 3x^3 + 2x^2 + x
00083 //  pf(2); // == 34
00084 // </srcblock>
00085 // </example>
00086 
00087 // <templating arg=T>
00088 //  <li> T should have standard numerical operators. Current
00089 //      implementation only tested for real types (and their AutoDiffs).
00090 // </templating>
00091 
00092 // <thrown>
00093 //    <li> Assertion in debug mode if attempt is made to address incorrect
00094 //              coefficients
00095 // </thrown>
00096 
00097 // <todo asof="2002/05/20">
00098 //   <li> Nothing I know of
00099 // </todo>
00100 
00101 template<class T> class SPolynomialParam: public Function<T>
00102 {
00103 public:
00104   //# Constructors
00105   // Constructs a zero'th order polynomial, with a coeficcient of 0.0.
00106   SPolynomialParam();
00107   
00108   // Makes a polynomial of the given order, with all coeficcients set to
00109   // zero. 
00110   explicit SPolynomialParam(uInt order);
00111   
00112   // Make this a copy of other (deep copy).
00113   // <group>
00114   SPolynomialParam(const SPolynomialParam<T> &other);
00115   template <class W>
00116     SPolynomialParam(const SPolynomialParam<W> &other) :
00117     Function<T>(other) {}
00118   SPolynomialParam<T> &operator=(const SPolynomialParam<T> &other);
00119   // </group>
00120   
00121   // Destructor
00122   ~SPolynomialParam();
00123 
00124   //# Operators  
00125   // Comparisons.  
00126   // SPolynomials are equal if they are of the same order
00127   // <group>
00128   Bool operator==(const SPolynomialParam<T> &other) const {
00129     return (param_p == other.param_p); }
00130   Bool operator!=(const SPolynomialParam<T> &other) const {
00131     return (param_p != other.param_p); }
00132   // </group>
00133 
00134   //# Member functions
00135   // Give name of function
00136   virtual const String &name() const { static String x("spolynomial");
00137     return x; }
00138 
00139   // What is the order of the polynomial, i.e. maximum exponent of "x".
00140   uInt order() const { return param_p.nelements() - 4; }
00141   
00142   // What is the <em>which</em>'th coefficient of the polynomial. For an nth
00143   // degree polynomial, <em>which</em> varies between zero and n.
00144   T coefficient(uInt which) const {
00145     DebugAssert(which<=order(), AipsError); return param_p[which+3]; }
00146   
00147   // Return all the coefficients as a vector.
00148   Vector<T> coefficients() const;
00149 
00150   // Set the <em>which</em>'th coefficient to <em>value</em>. 
00151   void setCoefficient(uInt which, const T value) {
00152     DebugAssert(which<=order(), AipsError); param_p[which+3] = value; }
00153   
00154   // Set all the coefficients at once, throw away all existing coefficients.
00155   void setCoefficients(const Vector<T> &coefficients);
00156 
00157   // Returns the dimension of function
00158   virtual uInt ndim() const { return 1; }
00159 
00160   //# Make members of parent classes known.
00161 protected:
00162   using Function<T>::param_p;
00163 public:
00164   using Function<T>::nparameters;
00165   using Function<T>::mask;
00166 };
00167 
00168 
00169 } //# NAMESPACE CASA - END
00170 
00171 #ifndef CASACORE_NO_AUTO_TEMPLATES
00172 #include <scimath/Functionals/SPolynomialParam.tcc>
00173 #endif //# CASACORE_NO_AUTO_TEMPLATES
00174 #endif