casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HyperPlane.h
Go to the documentation of this file.
1 //# HyperPlane.h: Form a hyper plane function
2 //# Copyright (C) 2001,2002,2004,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 //#
27 //# $Id$
28 
29 #ifndef SCIMATH_HYPERPLANE_H
30 #define SCIMATH_HYPERPLANE_H
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
38 
39 namespace casacore { //# NAMESPACE CASACORE - BEGIN
40 
41 // <summary> A hyper plane function.
42 // </summary>
43 //
44 // <use visibility=export>
45 // <reviewed reviewer="wbrouw" date="2004/05/25" tests="tHyperPlane" demos="">
46 // </reviewed>
47 //
48 // <prerequisite>
49 // <li> <linkto class=Function>Function</linkto>
50 // </prerequisite>
51 //
52 // <synopsis>
53 // This class forms a function of the form
54 // f(x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>) =
55 // p<sub>0</sub>*x<sub>0</sub> + p<sub>1</sub>*x<sub>1</sub> + ...
56 // + p<sub>m-1</sub>*x<sub>m-1</sub>,
57 // where p<sub>i</sub> are coefficients (parameters) and x<sub>i</sub>
58 // are independent arguments.
59 //
60 // f(x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>) represents a hyper plane
61 // of dimension <src>m</src>.
62 //
63 // Since the <src>HyperPlane</src> is a <src>Function</src>, the derivatives
64 // can be obtained as well.
65 //
66 // The parameter interface (see
67 // <linkto class="FunctionParam">FunctionParam</linkto> class),
68 // is used to provide an interface to the
69 // <linkto module="Fitting">Fitting</linkto> classes.
70 //
71 // This class is in general used implicitly by the <src>HyperPlane</src>
72 // class only.
73 // </synopsis>
74 //
75 // <example>
76 // <srcblock>
77 // // form the hyper plane function of this form:
78 // // 6*x0 + 2*x3
79 // HyperPlane<Double> hyper(4); // 4-dim hyperplane
80 // hyper.parameters()[0] = 6;
81 // hyper.parameters()[3] = 2;
82 // // Evaluate at x0=5, x3=7
83 // Vector<Double> x(4);
84 // x=0; x[0]=5; x[3]=7;
85 // cout << "Hypervalue: " << hyper(x) << endl;
86 // Hypervalue: 44
87 // </srcblock>
88 // </example>
89 
90 // <templating arg=T>
91 // <li> T should have standard numerical operators. Current
92 // implementation only tested for real types (and their AutoDiffs).
93 // </templating>
94 
95 // <thrown>
96 // <li> Assertion in debug mode if attempt is made to address incorrect
97 // coefficients
98 // </thrown>
99 
100 // <motivation>
101 // This class was created to allow the creation of linear constraint functions
102 // for the use of linear least-squares fit.
103 // </motivation>
104 //
105 // <todo asof="2004/05/25>
106 // <li> Nothing I know of
107 // </todo>
108 
109 template<class T> class HyperPlane : public HyperPlaneParam<T>
110 {
111 public:
112  //# Constructors
113  // Construct an m-dimensional hyper plane which has m parameters. By
114  // default, the coefficients are initialised to zero, and <src>m=0</src>
115  explicit HyperPlane(const uInt m=0) : HyperPlaneParam<T>(m) {;}
116  // Copy constructor/assignment (deep copy)
117  // <group>
118  HyperPlane(const HyperPlane<T> &other) : HyperPlaneParam<T>(other) {}
119  template <class W>
120  HyperPlane(const HyperPlane<W> &other) : HyperPlaneParam<T>(other) {}
122  HyperPlaneParam<T>::operator=(other); return *this; }
123  // </group>
124 
125  // Destructor
126  virtual ~HyperPlane() {}
127 
128  //# Operators
129  // Evaluate the hyper plane function at
130  // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
131  virtual T eval(typename Function<T>::FunctionArg x) const;
132 
133  // Return a copy of this object from the heap. The caller is responsible for
134  // deleting the pointer.
135  // <group>
136  virtual Function<T> *clone() const { return new HyperPlane<T>(*this); }
141  // </group>
142 
143  //# Make members of parent classes known.
144 protected:
146 public:
148 };
149 
150 #define HyperPlane_PS HyperPlane
151 
152 // <summary> Partial specialization of HyperPlane for <src>AutoDiff</src>
153 // </summary>
154 
155 // <synopsis>
156 // <note role=warning> The name <src>HyperPlane_PS</src> is only for cxx2html
157 // documentation problems. Use <src>HyperPlane</src> in your code.</note>
158 // </synopsis>
160 template <class T> class HyperPlane_PS<AutoDiff<T> > :
161 public HyperPlaneParam<AutoDiff<T> >
162 {
163 public:
164  //# Construct
165  // Constructors an m-dimensional hyper plane which has m parameters. By
166  // default, the coefficients are initialized to zero, and <src>m=0</src>
167  explicit HyperPlane_PS(const uInt m=0) :
168  HyperPlaneParam<AutoDiff<T> >(m) {}
169  // Copy constructor/assignment (deep copy)
170  // <group>
171  HyperPlane_PS(const HyperPlane_PS<AutoDiff<T> > &other) :
172  HyperPlaneParam<AutoDiff<T> >(other) {}
173  template <class W>
174  HyperPlane_PS(const HyperPlane_PS<W> &other) :
175  HyperPlaneParam<AutoDiff<T> >(other) {}
176  HyperPlane_PS<AutoDiff<T> > &
177  operator=(const HyperPlane_PS<AutoDiff<T> > &other) {
178  HyperPlaneParam<AutoDiff<T> >::operator=(other); return *this; }
179  // </group>
180 
181  // Destructor
182  virtual ~HyperPlane() {}
183 
184  //# Operators
185  // Evaluate the hyper plane function at
186  // (x<sub>0</sub>,x<sub>1</sub>,..,x<sub>m-1</sub>).
187  virtual AutoDiff<T>
188  eval(typename Function<AutoDiff<T> >::FunctionArg x) const;
189 
190  // Return a copy of this object from the heap. The caller is responsible for
191  // deleting the pointer.
192  // <group>
193  virtual Function<AutoDiff<T> > *clone() const {
194  return new HyperPlane_PS<AutoDiff<T> >(*this); }
196  *cloneAD() const {
197  return new HyperPlane<typename FunctionTraits<AutoDiff<T> >::DiffType>
198  (*this); }
200  *cloneNonAD() const {
201  return new HyperPlane<typename FunctionTraits<AutoDiff<T> >::BaseType>
202  (*this); }
203  // </group>
204 
205  //# Make members of parent classes known.
206 protected:
207  using HyperPlaneParam<AutoDiff<T> >::param_p;
208 public:
209  using HyperPlaneParam<AutoDiff<T> >::nparameters;
210 };
211 
212 #undef HyperPlane_PS
213 
214 
215 } //# NAMESPACE CASACORE - END
216 
217 #ifndef CASACORE_NO_AUTO_TEMPLATES
218 #include <casacore/scimath/Functionals/HyperPlane.tcc>
219 #include <casacore/scimath/Functionals/HyperPlane2.tcc>
220 #endif //# CASACORE_NO_AUTO_TEMPLATES
221 #endif
HyperPlane(const HyperPlane< T > &other)
Copy constructor/assignment (deep copy)
Definition: HyperPlane.h:118
PtrHolder< T > & operator=(const PtrHolder< T > &other)
HyperPlane< T > & operator=(const HyperPlane< T > &other)
Definition: HyperPlane.h:121
#define HyperPlane_PS
Definition: HyperPlane.h:150
A hyper plane function.
Definition: HyperPlane.h:109
virtual T eval(typename Function< T >::FunctionArg x) const
Evaluate the hyper plane function at (x0,x1,..,xm-1).
virtual Function< typename FunctionTraits< T >::BaseType > * cloneNonAD() const
Definition: HyperPlane.h:139
Parameter handling for a hyper plane function.
virtual Function< T > * clone() const
Return a copy of this object from the heap.
Definition: HyperPlane.h:136
Numerical functional interface class.
Definition: GenericL2Fit.h:46
virtual Function< typename FunctionTraits< T >::DiffType > * cloneAD() const
Definition: HyperPlane.h:137
HyperPlaneParam< T > & operator=(const HyperPlaneParam< T > &other)
Copy assignment (deep copy)
Class that computes partial derivatives by automatic differentiation.
Definition: AutoDiff.h:257
HyperPlane(const HyperPlane< W > &other)
Definition: HyperPlane.h:120
HyperPlane(const uInt m=0)
Construct an m-dimensional hyper plane which has m parameters.
Definition: HyperPlane.h:115
virtual ~HyperPlane()
Destructor.
Definition: HyperPlane.h:126
unsigned int uInt
Definition: aipstype.h:51