casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
NonLinearFitLM.h
Go to the documentation of this file.
00001 //# NonLinearFitLM.h: Solve non-linear fit using Levenberg-Marquardt method.
00002 //# Copyright (C) 1995,1999-2002,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 //#
00027 //# $Id: NonLinearFitLM.h 20229 2008-01-29 15:19:06Z gervandiepen $
00028 
00029 #ifndef SCIMATH_NONLINEARFITLM_H
00030 #define SCIMATH_NONLINEARFITLM_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <scimath/Fitting/NonLinearFit.h>
00035 namespace casa { //# begin namespace casa
00036 //# Forward declarations
00037 
00038 //
00039 // <summary>
00040 // Solve non-linear fit with Levenberg-Marquardt method.
00041 // </summary>
00042 //
00043 // <reviewed reviewer="wbrouw" date="2004/06/15" tests="tNonLinearFitLM.cc"
00044 //       demos="">
00045 // </reviewed>
00046 //
00047 // <prerequisite>
00048 //   <li> <linkto class="NonLinearFit">NonLinearFit</linkto>
00049 //   <li> <linkto module="Fitting">Fitting</linkto>
00050 // </prerequisite>
00051 //
00052 // <etymology>
00053 // This class uses the Levenberg-Marquardt method to solve the non-linear
00054 // least-squares fit problem hence NonLinearFitLM
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // NOTE: Constraints added. Documentation out of date at moment, check
00059 // the tLinearFitSVD and tNonLinearFirLM programs for examples.
00060 //
00061 // See the <linkto class=NonLinearFit>NonLinearFit</linkto> class for a
00062 // general description.
00063 //
00064 // This class is derived from the general NonLinearFit class. It does
00065 // a non-linear least-squares fit using the Levenberg-Marquardt method.
00066 //
00067 // See Numerical Recipes for more information
00068 // on the Levenberg-Marquardt method.
00069 // </synopsis>
00070 // 
00071 // <templating arg=T>
00072 // <li> Float
00073 // <li> Double
00074 // <li> Complex
00075 // <li> DComplex   
00076 // </templating>
00077 //
00078 // <motivation>
00079 // Levenberg-Marquardt method is a standard method for non-linear
00080 // least-squares fits.  It works well in practice over a wide range of
00081 // problems.
00082 // </motivation>
00083 // 
00084 // <example>
00085 // </example>
00086 
00087 template<class T> class NonLinearFitLM : public NonLinearFit<T>
00088 {
00089 public:
00090   //# Constructors
00091   // Create a fitter: the normal way to generate a fitter object. Necessary
00092   // data will be deduced from the Functional provided with
00093   // <src>setFunction()</src>.
00094   // Optionally, a fitter with SVD behaviour
00095   explicit NonLinearFitLM(Bool svd=False);
00096   // Copy constructor (deep copy)
00097   NonLinearFitLM(const NonLinearFitLM &other);
00098   // Assignment (deep copy)
00099   NonLinearFitLM &operator=(const NonLinearFitLM &other);
00100   
00101   // Destructor
00102   virtual ~NonLinearFitLM();
00103 
00104 protected:
00105   //# Member functions
00106   // Generalised fitter
00107   virtual Bool fitIt
00108     (Vector<typename FunctionTraits<T>::BaseType> &sol, 
00109      const Array<typename FunctionTraits<T>::BaseType> &x, 
00110      const Vector<typename FunctionTraits<T>::BaseType> &y,
00111      const Vector<typename FunctionTraits<T>::BaseType> *const sigma,
00112      const Vector<Bool> *const mask=0);
00113   
00114 private:
00115   //# Data
00116   // The parameter that makes this the Levenberg-Marquardt method.  
00117   Double lamda_p;
00118   // The current fit state
00119   Double fitit_p;
00120 
00121 protected:
00122   //# Make members of parent classes known.
00123   using NonLinearFit<T>::curiter_p;
00124   using NonLinearFit<T>::maxiter_p;
00125   using NonLinearFit<T>::converge_p;
00126   using NonLinearFit<T>::pCount_p;
00127   using NonLinearFit<T>::ptr_derive_p;
00128   using NonLinearFit<T>::sol_p;
00129   using NonLinearFit<T>::solved_p;
00130   using NonLinearFit<T>::nr_p;
00131   using NonLinearFit<T>::svd_p;
00132   using NonLinearFit<T>::condEq_p;
00133   using NonLinearFit<T>::err_p;
00134   using NonLinearFit<T>::errors_p;
00135   using NonLinearFit<T>::valder_p;
00136   using NonLinearFit<T>::buildConstraint;
00137   using NonLinearFit<T>::setMaskedParameterValues;
00138   using NonLinearFit<T>::fillSVDConstraints;
00139   using NonLinearFit<T>::isReady;
00140 };
00141 
00142 } //# End namespace casa
00143 #ifndef CASACORE_NO_AUTO_TEMPLATES
00144 #include <scimath/Fitting/NonLinearFitLM.tcc>
00145 #endif //# CASACORE_NO_AUTO_TEMPLATES
00146 #endif