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