casa
$Rev:20696$
|
00001 //# Sinusoid1D.h: A one dimensional Sinusoid class 00002 //# Copyright (C) 1997,2001,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: Sinusoid1D.h 21115 2011-07-21 09:28:38Z gervandiepen $ 00027 00028 #ifndef SCIMATH_SINUSOID1D_H 00029 #define SCIMATH_SINUSOID1D_H 00030 00031 //# Includes 00032 #include <casa/aips.h> 00033 #include <scimath/Functionals/Sinusoid1DParam.h> 00034 #include <scimath/Functionals/Function1D.h> 00035 #include <scimath/Mathematics/AutoDiff.h> 00036 #include <scimath/Mathematics/AutoDiffMath.h> 00037 00038 namespace casa { //# NAMESPACE CASA - BEGIN 00039 00040 //# Forward declarations 00041 00042 // <summary> A one dimensional Sinusoid class. 00043 // </summary> 00044 00045 // <use visibility=export> 00046 00047 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tSinusoid1D" 00048 // demos=""> 00049 // </reviewed> 00050 00051 // <prerequisite> 00052 // <li> <linkto class="Sinusoid1DParam">Sinusoid1DParam</linkto> 00053 // <li> <linkto class="Function">Function</linkto> 00054 // </prerequisite> 00055 00056 // <etymology> 00057 // A Sinusoid1D functional is designed for calculating a 00058 // Sinusoid in one dimension. 00059 // </etymology> 00060 00061 // <synopsis> 00062 // A <src>Sinusoid1D</src> is described by an amplitude, a period, 00063 // and a location of a peak. Its fundamental operation is evaluating itself 00064 // at some <src>x</src>. The 00065 // parameters (amplitude, period, and x0) may be changed at run time. 00066 // 00067 // The functional form is <src> A*cos(2*pi(x-x0)/P) </src> 00068 // 00069 // The parameter interface (see 00070 // <linkto class="Sinusoid1DParam">Sinusoid1DParam</linkto> class), 00071 // is used to provide an interface to the 00072 // <linkto module="Fitting"> Fitting </linkto> classes. 00073 // 00074 // There are 3 parameters that are used to describe the Sinusoid: 00075 // <ol> 00076 // <li> The amplitude of the Sinusoid. This is the value 00077 // returned using the <src> amplitude </src> member function. 00078 // <li> The period of the Sinusoid in the x direction. This is 00079 // the value returned using the <src> period </src> member function. 00080 // The period is expressed in full cycles. 00081 // <li> The location of a peak of the Sinusoid (i.e. where 00082 // <src>x=pi+k.2pi</src>) 00083 // </ol> 00084 // 00085 // An enumeration for the <src>AMPLITUDE</src>, <src>PERIOD</src> and 00086 // <src>X0</src> parameter index is provided, enabling the setting 00087 // and reading of parameters with the <src>[]</src> operator. The 00088 // <src>mask()</src> methods can be used to check and set the parameter masks. 00089 // 00090 // </synopsis> 00091 00092 // <example> 00093 // <srcblock> 00094 // Sinusoid1D<Double> sf(5.0, 25.0, 7); 00095 // sf(25); // = -0.9369 00096 // sf.setAmplitude(1.0); 00097 // sf[PERIOD] = 2.0; 00098 // sf.setX0(0.0); 00099 // sf(0.5); // = 0.0 00100 // </srcblock> 00101 // </example> 00102 00103 // <templating arg=T> 00104 // <li> T should have standard numerical operators and cos() function. Current 00105 // implementation only tested for real types. 00106 // <li> To obtain derivatives, the derivatives should be defined. 00107 // </templating> 00108 00109 // <thrown> 00110 // <li> AipsError if incorrect parameter number specified. 00111 // <li> Assertion in debug mode if operator(Vector<>) with empty Vector 00112 // </thrown> 00113 00114 template<class T> class Sinusoid1D : public Sinusoid1DParam<T> 00115 { 00116 public: 00117 //# Enumerations 00118 00119 //# Constructors 00120 // Constructs the Sinusoids, Defaults: 00121 // amplitude=1, period==1, x0=0. I.e. a cosinusoid with <src>cos(x)</src>. 00122 // <note role=warning> Could not use default arguments 00123 // that worked both with gcc and IRIX </note> 00124 // <group> 00125 Sinusoid1D() : Sinusoid1DParam<T>() {} 00126 explicit Sinusoid1D(const T &litude) : 00127 Sinusoid1DParam<T>(amplitude) {} 00128 Sinusoid1D(const T &litude, const T &period) : 00129 Sinusoid1DParam<T>(amplitude, period) {} 00130 Sinusoid1D(const T &litude, const T &period, const T &x0) : 00131 Sinusoid1DParam<T>(amplitude, period, x0) {} 00132 // </group> 00133 00134 // Copy constructor (deep copy) 00135 // <group> 00136 Sinusoid1D(const Sinusoid1D &other) : Sinusoid1DParam<T>(other) {} 00137 template <class W> 00138 Sinusoid1D(const Sinusoid1D<W> &other) : Sinusoid1DParam<T>(other) {} 00139 // </group> 00140 00141 // Copy assignment (deep copy) 00142 Sinusoid1D<T> &operator=(const Sinusoid1D<T> &other) { 00143 Sinusoid1DParam<T>::operator=(other); return *this; } 00144 00145 // Destructor 00146 virtual ~Sinusoid1D() {} 00147 00148 //# Operators 00149 // Evaluate the Sinusoid at <src>x</src>. 00150 // If a vector is used as the argument only its first element is used. 00151 // <group> 00152 virtual T eval(typename Function1D<T>::FunctionArg x) const; 00153 // </group> 00154 00155 //# Member functions 00156 // Return a copy of this object from the heap. The caller is responsible 00157 // for deleting this pointer. 00158 // <group> 00159 virtual Function<T> *clone() const { return new Sinusoid1D<T>(*this); } 00160 virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const { 00161 return new Sinusoid1D<typename FunctionTraits<T>::DiffType>(*this); } 00162 virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const { 00163 return new Sinusoid1D<typename FunctionTraits<T>::BaseType>(*this); } 00164 // </group> 00165 00166 //# Make members of parent classes known. 00167 protected: 00168 using Sinusoid1DParam<T>::param_p; 00169 public: 00170 using Sinusoid1DParam<T>::nparameters; 00171 using Sinusoid1DParam<T>::AMPLITUDE; 00172 using Sinusoid1DParam<T>::PERIOD; 00173 using Sinusoid1DParam<T>::X0; 00174 }; 00175 00176 00177 #define Sinusoid1D_PS Sinusoid1D 00178 // <summary> Partial specialization of Sinusoid1D for <src>AutoDiff</src> 00179 // </summary> 00180 00181 // <synopsis> 00182 // <note role=warning> The name <src>Sinusoid1D_PS</src> is only for cxx2html 00183 // documentation problems. Use <src>Sinusoid1D</src> in your code.</note> 00184 // </synopsis> 00185 00186 template <class T> class Sinusoid1D_PS<AutoDiff<T> > : 00187 public Sinusoid1DParam<AutoDiff<T> > 00188 { 00189 public: 00190 //# Constructors 00191 // Constructs one dimensional Sinusoids. 00192 // <group> 00193 Sinusoid1D_PS() : Sinusoid1DParam<AutoDiff<T> >() {} 00194 explicit Sinusoid1D_PS(const AutoDiff<T> &litude) : 00195 Sinusoid1DParam<AutoDiff<T> >(amplitude) {} 00196 Sinusoid1D_PS(const AutoDiff<T> &litude, const AutoDiff<T> &period) : 00197 Sinusoid1DParam<AutoDiff<T> >(amplitude, period) {} 00198 Sinusoid1D_PS(const AutoDiff<T> &litude, const AutoDiff<T> &period, 00199 const AutoDiff<T> &x0) : 00200 Sinusoid1DParam<AutoDiff<T> >(amplitude, period, x0) {} 00201 // </group> 00202 00203 // Copy constructor (deep copy) 00204 // <group> 00205 Sinusoid1D_PS(const Sinusoid1D_PS &other) : 00206 Sinusoid1DParam<AutoDiff<T> >(other) {} 00207 template <class W> 00208 Sinusoid1D_PS(const Sinusoid1D_PS<W> &other) : 00209 Sinusoid1DParam<AutoDiff<T> >(other) {} 00210 // </group> 00211 00212 // Copy assignment (deep copy) 00213 Sinusoid1D_PS<AutoDiff<T> > & 00214 operator=(const Sinusoid1D_PS<AutoDiff<T> > &other) { 00215 Sinusoid1DParam<AutoDiff<T> >::operator=(other); return *this; } 00216 00217 // Destructor 00218 virtual ~Sinusoid1D_PS() {} 00219 00220 //# Operators 00221 // Evaluate the Sinusoid at <src>x</src>. 00222 // <group> 00223 virtual AutoDiff<T> 00224 eval(typename Function<AutoDiff<T> >::FunctionArg x) const; 00225 // </group> 00226 00227 //# Member functions 00228 // Return a copy of this object from the heap. The caller is responsible 00229 // for deleting this pointer. 00230 // <group> 00231 virtual Function<AutoDiff<T> > *clone() const { 00232 return new Sinusoid1D<AutoDiff<T> >(*this); } 00233 virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType> 00234 *cloneAD() const { 00235 return new Sinusoid1D<typename FunctionTraits<AutoDiff<T> >::DiffType> 00236 (*this); } 00237 virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType> 00238 *cloneNonAD() const { 00239 return new Sinusoid1D<typename FunctionTraits<AutoDiff<T> >::BaseType> 00240 (*this); } 00241 // </group> 00242 00243 protected: 00244 //# Make members of parent classes known. 00245 using Sinusoid1DParam<AutoDiff<T> >::param_p; 00246 using Sinusoid1DParam<AutoDiff<T> >::nparameters; 00247 using Sinusoid1DParam<AutoDiff<T> >::AMPLITUDE; 00248 using Sinusoid1DParam<AutoDiff<T> >::PERIOD; 00249 using Sinusoid1DParam<AutoDiff<T> >::X0; 00250 }; 00251 00252 #undef Sinusoid1D_PS 00253 00254 } //# NAMESPACE CASA - END 00255 00256 #ifndef CASACORE_NO_AUTO_TEMPLATES 00257 #include <scimath/Functionals/Sinusoid1D.tcc> 00258 #include <scimath/Functionals/Sinusoid1D2.tcc> 00259 #endif //# CASACORE_NO_AUTO_TEMPLATES 00260 #endif