casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Fitting.h
Go to the documentation of this file.
00001 //# Fitting.h: Module for various forms of mathematical fitting
00002 //# Copyright (C) 1995,1999-2002,2004
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: Fitting.h 20670 2009-07-10 01:43:43Z Malte.Marquarding $
00027 #ifndef SCIMATH_FITTING_H
00028 #define SCIMATH_FITTING_H
00029 
00030 #include <casa/aips.h>
00031 #include <scimath/Fitting/LSQFit.h>
00032 #include <scimath/Fitting/LinearFit.h>
00033 #include <scimath/Fitting/LinearFitSVD.h>
00034 #include <scimath/Fitting/NonLinearFit.h>
00035 #include <scimath/Fitting/NonLinearFitLM.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <module>
00040 //
00041 // <summary>
00042 // Module for various forms of mathematical fitting. 
00043 // </summary>
00044 //
00045 // <prerequisite>
00046 // <li> Basic principles can be found in 
00047 //      <a href="../notes/224.html">Note 224</a>.
00048 // </prerequisite>
00049 //
00050 // <reviewed reviewer="Neil Killeen" date="2000/06/01"
00051 //       demos="dLSQFit,dConstraints">
00052 // </reviewed>
00053 //
00054 // <synopsis> 
00055 //
00056 // The Fitting module holds various classes and functions related
00057 // to fitting models to data.  Currently only least-squares fits
00058 // are handled.
00059 //
00060 // <H3>Least-Squares Fits</H3>
00061 //
00062 // We are given N data points, which
00063 // we will fit to a function with M adjustable parameters. 
00064 // N should normally be greater than M, and at least M non-dependent relations
00065 // between the parameters should be given. In cases where there are less than
00066 // M independent points, Singular-Value-Deconvolution methods are available.
00067 // Each condition equation can be given an  
00068 // (estimated) standard deviation, which is comparable to the statistical
00069 // weight, which is often used in place of the standard deviation.
00070 // 
00071 // The best fit is assumed to be the one which minimises the 'chi-squared'.
00072 //
00073 // In the (rather common) case that individual errors are not known for
00074 // the individual data points, one can <em>assume</em> that the
00075 // individual errors are unity, calculate the best fit function, and then
00076 // <em>estimate</em> the errors (assuming they are all identical) by
00077 // inverting the <em>normal equations</em>.
00078 // Of course, in this case we do not have an independent estimate of
00079 // chi<sup>2</sup>.
00080 //
00081 // The methods used in the Fitting module are described in aips++ 
00082 // <a href="../notes/224.html">Note 224</a>.
00083 // The methods (both standard and
00084 // SVD) are based on a Cholesky decomposition of the normal equations.
00085 //
00086 // General background can also be found in <EM>Numerical Recipes</EM> by 
00087 // Press <EM>et al.</EM>.
00088 //
00089 // <H3>Linear Least-Squares Fits</H3>
00090 //
00091 // The <em>linear least squares</em> solution assumes that the fit function
00092 // is a linear combination of M linear condition equations.
00093 // It is important to note that <em>linear</em> refers to the dependence on
00094 // the parameters; the condition equations may be very non-linear in the
00095 // dependent arguments.
00096 //
00097 // The linear least squares problem is solved by explicitly
00098 // forming and inverting the normal equations.
00099 // If the normal equations are close to
00100 // singular, the <em>singular value decomposition</em> (SVD) method may be 
00101 // used. <em>Numerical Recipes</em> suggests the SVD be always used, however 
00102 // this advice is not universally accepted.
00103 //
00104 // <H3>Linear Least-Squares Fits with Known Linear Constraints</H3>
00105 //
00106 // Sometimes there are not enough independent observations, <EM>i.e.</EM>, the
00107 // number of data points <I>N</I> is less than the number of adjustable
00108 // parameters <I>M</I>.  In this case the least-squares problem cannot be
00109 // solved unless additional ``constraints'' on the adjustable parameters can
00110 // be introduced.  Under other circumstances, we may want to introduce
00111 // constraints on the adjustable 
00112 // parameters to add additional information, <EM>e.g.</EM>, the sum of angles 
00113 // of a triangle.  In more complex cases, the forms of the constraints 
00114 // are unknown.  Here we confine ourselves to
00115 // least-squares fit problems in which the forms of constraints are known.
00116 //
00117 // If the forms of constraint equations are known, the least-squares
00118 // problem can be solved.  (In the case where not 
00119 // enough independent observations are available, a minimum number of 
00120 // sufficient constraint equations have to be provided. The singular value
00121 // decomposition method can be used to calculate the minimum number of 
00122 // orthogonal constraints needed).
00123 // 
00124 // <H3>Nonlinear Least-Squares Fits</H3>
00125 //
00126 // We now consider the situation where the fitted function 
00127 // depends <EM>nonlinearly</EM> on the set of
00128 // <I>M</I> adjustable parameters.
00129 // But with nonlinear dependences the minimisation of chi<sup>2</sup> cannot
00130 // proceed as in the linear case.
00131 // However, we can <EM>linearise</EM> the problem, find an
00132 // approximate solution, and then iteratively seek the minimising solution. 
00133 // The iteration stops when e.g. the adjusted parameters do not change
00134 // anymore. In general it is very difficult to find a general solution that
00135 // finds a global minimum, and the solution has to be matched with the problem.
00136 // The Levenberg-Marquardt algorithm is a general non-linear fitting method
00137 // which can produce correct results in many cases. It has been included, but
00138 // always be aware of possible problems with non-linear solutions.
00139 //
00140 // <H3>What Is Available?</H3>
00141 //
00142 // The basic classes are <linkto class=LSQFit>LSQFit</linkto> and 
00143 //  <linkto class=LSQaips>LSQaips</linkto>.
00144 // They provide the basic  framework for normal equation generation, solving 
00145 // the normal equations and iterating in the case of non-linear equations. 
00146 //
00147 // The <em>LSQFit</em> class uses a native C++ interface (pointers and 
00148 // iterators). They handle real data and complex data.
00149 // The <em>LSQaips</em> class offers the functionality of <em>LSQFit</em>,
00150 // but with an additional aips++ Array interface.<br>
00151 //
00152 // Functionality is
00153 // <ol>
00154 // <li> Fit a linear combination of functions to data points, and, optionally,
00155 //      use supplied constraint conditions on the adjustable parameters.
00156 // <li> Fit a nonlinear function to data points.  The adjustable parameters
00157 //      are parameters inside the function.
00158 // <li> Repetitively perform a linear fit for every line of pixels parallel 
00159 //      to any axis in a Lattice.
00160 // <li> Solve (as opposed to fit to a set of data), a set of equations
00161 // </ol> 
00162 //
00163 // In addition to the basic Least Squares routines in the <src>LSQFit</src> and
00164 // <src>LSQaips</src> classes, this module contains also a set of direct
00165 // data fitters:
00166 // <ul>
00167 // <li> <src>Fit2D</src>
00168 // <li> <src>LinearFit</src>
00169 // <li> <src>LinearFitSVD</src>
00170 // <li> <src>NonLinearFit</src>
00171 // <li> <src>NonLinearFitLM</src>
00172 // </ul>
00173 // Furthermore class <src>LatticeFit</src> can do fitting on lattices.
00174 //
00175 // Note that the basic functions have <em>LSQ</em> in their title; the
00176 // one-step fitting functions <em>Fit</em>.
00177 //
00178 // The above fitting problems can usually be solved by directly 
00179 // calling the <src>fit()</src> member function provided by one of the
00180 // <src>Fit</src> classes above, or by 
00181 // gradually building the normal equation matrix and solving the
00182 // normal equations (<src>solve()</src>).  
00183 //  
00184 // A Distributed Object interface to the classes is available
00185 // (<src>DOfitting</src>) for use in the <I>Glish</I> <src>dfit</src>
00186 // object, available through the <src>fitting.g</src> script.
00187 //
00188 // </synopsis> 
00189 //
00190 // <motivation>
00191 // This module was motivated by baseline subtraction/continuum fitting in the
00192 // first instance.
00193 // </motivation>
00194 //
00195 // <todo asof="2004/09/22">
00196 //      <li> extend the Fit interface classes to cater for building the
00197 //              normal equations in parts.
00198 // </todo>
00199 //
00200 // </module>
00201 //
00202 
00203 } //# NAMESPACE CASA - END
00204 
00205 #endif
00206 
00207