casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LSQaips.h
Go to the documentation of this file.
00001 //# LSQaips.h: Interface for aips++ Vectors in least squares fitting
00002 //# Copyright (C) 1999,2000,2001,2004,2006
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: LSQaips.h 21024 2011-03-01 11:46:18Z gervandiepen $
00027 
00028 #ifndef SCIMATH_LSQAIPS_H
00029 #define SCIMATH_LSQAIPS_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Array.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <casa/Arrays/VectorSTLIterator.h>
00036 #include <scimath/Fitting/LSQFit.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 
00042 // <summary>
00043 // Interface for aips++ Vectors in least squares fitting
00044 // </summary>
00045 // <reviewed reviewer="" date="2004/04/01" tests=""
00046 //       demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class=LSQFit>LSQFit</linkto> class
00051 // </prerequisite>
00052 //
00053 // <etymology>
00054 // From Least SQuares and aips++
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // The interface used in the <src>LSQaips</src> class is in terms of
00059 // aips++ Vectors directly, rather than an STL iterator (like 
00060 // <linkto class=VectorSTLIterator>VectorSTLIterator</linkto>) based
00061 // on it.
00062 //
00063 // Its functionality is identical to that of the
00064 // <linkto class=LSQFit>LSQFit</linkto> class, although it will be faster to use
00065 // the iterator interface directly, since constructing of temporary iterators
00066 // can be avoided
00067 // </synopsis>
00068 //
00069 // <example>
00070 // See the <src>tLSQaips.cc</src> program for extensive examples.
00071 // Note: this class is in an interim state.
00072 // </example>
00073 //
00074 // <motivation>
00075 // The class was written to enable easy tranistion from the current Vector
00076 // to the Vector::iterator interface.
00077 // </motivation>
00078 //
00079 // <todo asof="2004/04/02">
00080 //   <li> create all the method interfaces
00081 // </todo>
00082 
00083 class LSQaips : public LSQFit {
00084  public:
00085   
00086   //# Constructors
00087   // Construct an object with the number of unknown, knowns and
00088   // constraints, and type, using the default collinearity factor and the
00089   // default Levenberg-Marquardt adjustment factor
00090   // <group>
00091   // Assume real
00092   LSQaips(uInt nUnknowns, uInt nConstraints=0)
00093   : LSQFit(nUnknowns, nConstraints) {;}
00094   // Allow explicit complex/real specification
00095   // <group>
00096   LSQaips(uInt nUnknowns, const LSQReal &, uInt nConstraints=0)
00097   : LSQFit(nUnknowns, LSQReal(), nConstraints) {;}
00098   LSQaips(uInt nUnknowns, const LSQComplex &, uInt nConstraints=0)
00099   : LSQFit(nUnknowns, LSQComplex(), nConstraints) {;}
00100   // </group>
00101   // </group>
00102   // Default constructor (empty, real, only usable after a set(nUnknowns))
00103   LSQaips() : LSQFit() {;}
00104   // Copy constructor (deep copy)
00105   LSQaips(const LSQaips &other) : LSQFit(other) {;}
00106   // Assignment (deep copy)
00107   LSQaips &operator=(const LSQaips &other) {
00108   if (this != &other) LSQFit::operator=(other);
00109   return *this; }
00110   
00111   //# Destructor
00112   ~LSQaips() {;}
00113   
00114   //# Operators
00115   
00116   //# General Member Functions
00117   // Solve normal equations.
00118   // The solution will be given in <src>sol</src>.
00119   // <group>
00120   template <class U>
00121   void solve(U *sol) { LSQFit::solve(sol); }
00122   template <class U>
00123   void solve(std::complex<U> *sol) { LSQFit::solve(sol); }
00124   template <class U>
00125   void solve(U &sol) { LSQFit::solve(sol); }
00126   template <class U>
00127   void solve(Vector<U> &sol) {
00128     sol.resize(nUnknowns()/LSQTraits<U>::size);
00129     LSQFit::solve(sol.data()); }
00130   // </group>
00131   // Solve a Levenberg-Marquardt loop. Note that the solution <src>sol</src>
00132   // is used both and input and output. No check on the size is done.
00133   // <group>
00134   template <class U>
00135   Bool solveLoop(uInt &nRank,
00136                  U *sol, Bool doSVD=False) {
00137     return LSQFit::solveLoop(nRank, sol, doSVD); }
00138   template <class U>
00139   Bool solveLoop(uInt &nRank,
00140                  std::complex<U> *sol, Bool doSVD=False) {
00141     return LSQFit::solveLoop(nRank, sol, doSVD); }
00142   template <class U>
00143   Bool solveLoop(uInt &nRank,
00144                  U &sol, Bool doSVD=False) {
00145     return LSQFit::solveLoop(nRank, sol, doSVD); }
00146   template <class U>
00147   Bool solveLoop(uInt &nRank,
00148                  Vector<U> &sol, Bool doSVD=False);
00149   template <class U>
00150   Bool solveLoop(Double &fit, uInt &nRank,
00151                  U *sol, Bool doSVD=False) {
00152     return LSQFit::solveLoop(fit, nRank, sol, doSVD); }
00153   template <class U>
00154   Bool solveLoop(Double &fit, uInt &nRank,
00155                  std::complex<U> *sol, Bool doSVD=False) {
00156     return LSQFit::solveLoop(fit, nRank, sol, doSVD); }
00157   template <class U>
00158   Bool solveLoop(Double &fit, uInt &nRank,
00159                  U &sol, Bool doSVD=False) {
00160     return LSQFit::solveLoop(fit, nRank, sol, doSVD); }
00161   template <class U>
00162   Bool solveLoop(Double &fit, uInt &nRank,
00163                  Vector<U> &sol, Bool doSVD=False);
00164   // </group>
00165   // Get the covariance matrix. False if an error occurred
00166   // (of size <src>nUnknowns * nUnknowns</src>)
00167   // <group>
00168   template <class U>
00169   Bool getCovariance(U *covar) {
00170     return LSQFit::getCovariance(covar); }
00171   template <class U>
00172   Bool getCovariance(std::complex<U> *covar) {
00173     return LSQFit::getCovariance(covar); }
00174   template <class U>
00175   Bool getCovariance(Array<U> &covar);
00176   // </group>  
00177   // Get main diagonal of covariance function (of size <src>nUnknowns</src>)
00178   // <group>
00179   template <class U>
00180   Bool getErrors(U *errors) {
00181     return LSQFit::getErrors(errors); }
00182   template <class U>
00183   Bool getErrors(std::complex<U> *errors) {
00184     return LSQFit::getErrors(errors); }
00185   template <class U>
00186   Bool getErrors(U &errors) {
00187     return LSQFit::getErrors(errors); }
00188   template <class U>
00189   Bool getErrors(Vector<U> &errors) {
00190     errors.resize(nUnknowns()/LSQTraits<U>::size);
00191     return LSQFit::getErrors(errors.data()); }
00192   // </group>
00193   
00194 private:
00195 
00196   //# Data
00197 
00198 };
00199 
00200 
00201 } //# NAMESPACE CASA - END
00202 
00203 #ifndef CASACORE_NO_AUTO_TEMPLATES
00204 #include <scimath/Fitting/LSQaips.tcc>
00205 #endif //# CASACORE_NO_AUTO_TEMPLATES
00206 #endif