casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
HyperPlane.h
Go to the documentation of this file.
00001 //# HyperPlane.h: Form a hyper plane function
00002 //# Copyright (C) 2001,2002,2004,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 //#
00027 //# $Id: HyperPlane.h 21024 2011-03-01 11:46:18Z gervandiepen $
00028 
00029 #ifndef SCIMATH_HYPERPLANE_H
00030 #define SCIMATH_HYPERPLANE_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <scimath/Functionals/HyperPlaneParam.h>
00035 #include <scimath/Functionals/Function.h>
00036 #include <scimath/Mathematics/AutoDiff.h>
00037 #include <scimath/Mathematics/AutoDiffMath.h>
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 // <summary> A hyper plane function.
00042 // </summary>
00043 //
00044 // <use visibility=export>
00045 // <reviewed reviewer="wbrouw" date="2004/05/25" tests="tHyperPlane" demos="">
00046 // </reviewed>
00047 //
00048 // <prerequisite>
00049 //   <li> <linkto class=Function>Function</linkto>
00050 // </prerequisite>
00051 //
00052 // <synopsis>
00053 // This class forms a function of the form
00054 // f(x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>) =
00055 // p<sub>0</sub>*x<sub>0</sub> + p<sub>1</sub>*x<sub>1</sub> + ...
00056 // + p<sub>m-1</sub>*x<sub>m-1</sub>, 
00057 // where p<sub>i</sub> are coefficients (parameters) and x<sub>i</sub>
00058 // are independent arguments.
00059 //
00060 // f(x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>) represents a hyper plane
00061 // of dimension <src>m</src>.
00062 //
00063 // Since the <src>HyperPlane</src> is a <src>Function</src>, the derivatives
00064 // can be obtained as well. 
00065 //
00066 // The parameter interface (see 
00067 // <linkto class="FunctionParam">FunctionParam</linkto> class), 
00068 // is used to provide an interface to the
00069 // <linkto module="Fitting">Fitting</linkto> classes. 
00070 //
00071 // This class is in general used implicitly by the <src>HyperPlane</src>
00072 // class only.
00073 // </synopsis>
00074 //
00075 // <example>
00076 // <srcblock>
00077 // // form the hyper plane function of this form: 
00078 // // 6*x0 + 2*x3 
00079 //  HyperPlane<Double> hyper(4); // 4-dim hyperplane
00080 //  hyper.parameters()[0] = 6;   
00081 //  hyper.parameters()[3] = 2;
00082 //  // Evaluate at x0=5, x3=7
00083 //  Vector<Double> x(4);
00084 //  x=0; x[0]=5; x[3]=7;
00085 //  cout << "Hypervalue: " << hyper(x) << endl;
00086 //  Hypervalue: 44
00087 // </srcblock>
00088 // </example>
00089 
00090 // <templating arg=T>
00091 //  <li> T should have standard numerical operators. Current
00092 //      implementation only tested for real types (and their AutoDiffs).
00093 // </templating>
00094 
00095 // <thrown>
00096 //    <li> Assertion in debug mode if attempt is made to address incorrect
00097 //         coefficients
00098 // </thrown>
00099 
00100 // <motivation>
00101 // This class was created to allow the creation of linear constraint functions
00102 // for the use of linear least-squares fit.
00103 // </motivation>
00104 //
00105 // <todo asof="2004/05/25>
00106 //  <li> Nothing I know of
00107 // </todo>
00108 
00109 template<class T> class HyperPlane : public HyperPlaneParam<T>
00110 {
00111 public:
00112   //# Constructors
00113   // Construct an m-dimensional hyper plane which has m parameters.  By 
00114   // default, the coefficients are initialised to zero, and <src>m=0</src>
00115   explicit HyperPlane(const uInt m=0) : HyperPlaneParam<T>(m) {;}
00116   // Copy constructor/assignment (deep copy)
00117   // <group>
00118   HyperPlane(const HyperPlane<T> &other) : HyperPlaneParam<T>(other) {}
00119   template <class W>
00120     HyperPlane(const HyperPlane<W> &other) : HyperPlaneParam<T>(other) {}
00121   HyperPlane<T> &operator=(const HyperPlane<T> &other) {
00122     HyperPlaneParam<T>::operator=(other); return *this; }
00123   // </group>
00124 
00125   // Destructor
00126   virtual ~HyperPlane() {}
00127 
00128   //# Operators    
00129   // Evaluate the hyper plane function at
00130   // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
00131   virtual T eval(typename Function<T>::FunctionArg x) const;
00132   
00133   // Return a copy of this object from the heap. The caller is responsible for
00134   // deleting the pointer.
00135   // <group>
00136   virtual Function<T> *clone() const { return new HyperPlane<T>(*this); }
00137   virtual Function<typename FunctionTraits<T>::DiffType> *cloneAD() const {
00138     return new HyperPlane<typename FunctionTraits<T>::DiffType>(*this); }
00139   virtual Function<typename FunctionTraits<T>::BaseType> *cloneNonAD() const {
00140     return new HyperPlane<typename FunctionTraits<T>::BaseType>(*this); }
00141   // </group>
00142 
00143   //# Make members of parent classes known.
00144 protected:
00145   using HyperPlaneParam<T>::param_p;
00146 public:
00147   using HyperPlaneParam<T>::nparameters;
00148 };
00149 
00150 #define HyperPlane_PS HyperPlane
00151 
00152 // <summary> Partial specialization of HyperPlane for <src>AutoDiff</src>
00153 // </summary>
00154 
00155 // <synopsis>
00156 // <note role=warning> The name <src>HyperPlane_PS</src> is only for cxx2html
00157 // documentation problems. Use <src>HyperPlane</src> in your code.</note>
00158 // </synopsis>
00159 
00160 template <class T> class HyperPlane_PS<AutoDiff<T> > : 
00161 public HyperPlaneParam<AutoDiff<T> >
00162 {
00163 public:
00164   //# Construct
00165   // Constructors an m-dimensional hyper plane which has m parameters.  By 
00166   // default, the coefficients are initialized to zero, and <src>m=0</src>
00167   explicit HyperPlane_PS(const uInt m=0) :
00168     HyperPlaneParam<AutoDiff<T> >(m) {}
00169   // Copy constructor/assignment (deep copy)
00170   // <group>
00171   HyperPlane_PS(const HyperPlane_PS<AutoDiff<T> > &other) :
00172     HyperPlaneParam<AutoDiff<T> >(other) {}
00173   template <class W>
00174     HyperPlane_PS(const HyperPlane_PS<W> &other) :
00175     HyperPlaneParam<AutoDiff<T> >(other) {}
00176   HyperPlane_PS<AutoDiff<T> > &
00177     operator=(const HyperPlane_PS<AutoDiff<T> > &other) {
00178     HyperPlaneParam<AutoDiff<T> >::operator=(other); return *this; }
00179   // </group>
00180   
00181   // Destructor
00182   virtual ~HyperPlane() {}
00183   
00184   //# Operators    
00185   // Evaluate the hyper plane function at
00186   // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
00187   virtual AutoDiff<T> 
00188     eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
00189   
00190   // Return a copy of this object from the heap. The caller is responsible for
00191   // deleting the pointer.
00192   // <group>
00193   virtual Function<AutoDiff<T> > *clone() const {
00194     return new HyperPlane_PS<AutoDiff<T> >(*this); }
00195   virtual Function<typename FunctionTraits<AutoDiff<T> >::DiffType>
00196     *cloneAD() const {
00197     return new HyperPlane<typename FunctionTraits<AutoDiff<T> >::DiffType>
00198       (*this); }
00199   virtual Function<typename FunctionTraits<AutoDiff<T> >::BaseType>
00200     *cloneNonAD() const {
00201     return new HyperPlane<typename FunctionTraits<AutoDiff<T> >::BaseType>
00202       (*this); }
00203   // </group>
00204 
00205   //# Make members of parent classes known.
00206 protected:
00207   using HyperPlaneParam<AutoDiff<T> >::param_p;
00208 public:
00209   using HyperPlaneParam<AutoDiff<T> >::nparameters;
00210 };
00211 
00212 #undef HyperPlane_PS
00213 
00214 
00215 } //# NAMESPACE CASA - END
00216 
00217 #ifndef CASACORE_NO_AUTO_TEMPLATES
00218 #include <scimath/Functionals/HyperPlane.tcc>
00219 #include <scimath/Functionals/HyperPlane2.tcc>
00220 #endif //# CASACORE_NO_AUTO_TEMPLATES
00221 #endif