casacore
Loading...
Searching...
No Matches
Fitting.h
Go to the documentation of this file.
1//# Fitting.h: Module for various forms of mathematical fitting
2//# Copyright (C) 1995,1999-2002,2004
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#ifndef SCIMATH_FITTING_H
26#define SCIMATH_FITTING_H
27
28#include <casacore/casa/aips.h>
29#include <casacore/scimath/Fitting/LSQFit.h>
30#include <casacore/scimath/Fitting/LinearFit.h>
31#include <casacore/scimath/Fitting/LinearFitSVD.h>
32#include <casacore/scimath/Fitting/NonLinearFit.h>
33#include <casacore/scimath/Fitting/NonLinearFitLM.h>
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37// <module>
38//
39// <summary>
40// Module for various forms of mathematical fitting.
41// </summary>
42//
43// <prerequisite>
44// <li> Basic principles can be found in
45// <a href="../notes/224.html">Note 224</a>.
46// </prerequisite>
47//
48// <reviewed reviewer="Neil Killeen" date="2000/06/01"
49// demos="dLSQFit,dConstraints">
50// </reviewed>
51//
52// <synopsis>
53//
54// The Fitting module holds various classes and functions related
55// to fitting models to data. Currently only least-squares fits
56// are handled.
57//
58// <H3>Least-Squares Fits</H3>
59//
60// We are given N data points, which
61// we will fit to a function with M adjustable parameters.
62// N should normally be greater than M, and at least M non-dependent relations
63// between the parameters should be given. In cases where there are less than
64// M independent points, Singular-Value-Deconvolution methods are available.
65// Each condition equation can be given an
66// (estimated) standard deviation, which is comparable to the statistical
67// weight, which is often used in place of the standard deviation.
68//
69// The best fit is assumed to be the one which minimises the 'chi-squared'.
70//
71// In the (rather common) case that individual errors are not known for
72// the individual data points, one can <em>assume</em> that the
73// individual errors are unity, calculate the best fit function, and then
74// <em>estimate</em> the errors (assuming they are all identical) by
75// inverting the <em>normal equations</em>.
76// Of course, in this case we do not have an independent estimate of
77// chi<sup>2</sup>.
78//
79// The methods used in the Fitting module are described in
80// <a href="../notes/224.html">Note 224</a>.
81// The methods (both standard and
82// SVD) are based on a Cholesky decomposition of the normal equations.
83//
84// General background can also be found in <EM>Numerical Recipes</EM> by
85// Press <EM>et al.</EM>.
86//
87// <H3>Linear Least-Squares Fits</H3>
88//
89// The <em>linear least squares</em> solution assumes that the fit function
90// is a linear combination of M linear condition equations.
91// It is important to note that <em>linear</em> refers to the dependence on
92// the parameters; the condition equations may be very non-linear in the
93// dependent arguments.
94//
95// The linear least squares problem is solved by explicitly
96// forming and inverting the normal equations.
97// If the normal equations are close to
98// singular, the <em>singular value decomposition</em> (SVD) method may be
99// used. <em>Numerical Recipes</em> suggests the SVD be always used, however
100// this advice is not universally accepted.
101//
102// <H3>Linear Least-Squares Fits with Known Linear Constraints</H3>
103//
104// Sometimes there are not enough independent observations, <EM>i.e.</EM>, the
105// number of data points <I>N</I> is less than the number of adjustable
106// parameters <I>M</I>. In this case the least-squares problem cannot be
107// solved unless additional ``constraints'' on the adjustable parameters can
108// be introduced. Under other circumstances, we may want to introduce
109// constraints on the adjustable
110// parameters to add additional information, <EM>e.g.</EM>, the sum of angles
111// of a triangle. In more complex cases, the forms of the constraints
112// are unknown. Here we confine ourselves to
113// least-squares fit problems in which the forms of constraints are known.
114//
115// If the forms of constraint equations are known, the least-squares
116// problem can be solved. (In the case where not
117// enough independent observations are available, a minimum number of
118// sufficient constraint equations have to be provided. The singular value
119// decomposition method can be used to calculate the minimum number of
120// orthogonal constraints needed).
121//
122// <H3>Nonlinear Least-Squares Fits</H3>
123//
124// We now consider the situation where the fitted function
125// depends <EM>nonlinearly</EM> on the set of
126// <I>M</I> adjustable parameters.
127// But with nonlinear dependences the minimisation of chi<sup>2</sup> cannot
128// proceed as in the linear case.
129// However, we can <EM>linearise</EM> the problem, find an
130// approximate solution, and then iteratively seek the minimising solution.
131// The iteration stops when e.g. the adjusted parameters do not change
132// anymore. In general it is very difficult to find a general solution that
133// finds a global minimum, and the solution has to be matched with the problem.
134// The Levenberg-Marquardt algorithm is a general non-linear fitting method
135// which can produce correct results in many cases. It has been included, but
136// always be aware of possible problems with non-linear solutions.
137//
138// <H3>What Is Available?</H3>
139//
140// The basic classes are <linkto class=LSQFit>LSQFit</linkto> and
141// <linkto class=LSQaips>LSQaips</linkto>.
142// They provide the basic framework for normal equation generation, solving
143// the normal equations and iterating in the case of non-linear equations.
144//
145// The <em>LSQFit</em> class uses a native C++ interface (pointers and
146// iterators). They handle real data and complex data.
147// The <em>LSQaips</em> class offers the functionality of <em>LSQFit</em>,
148// but with an additional Casacore Array interface.<br>
149//
150// Functionality is
151// <ol>
152// <li> Fit a linear combination of functions to data points, and, optionally,
153// use supplied constraint conditions on the adjustable parameters.
154// <li> Fit a nonlinear function to data points. The adjustable parameters
155// are parameters inside the function.
156// <li> Repetitively perform a linear fit for every line of pixels parallel
157// to any axis in a Lattice.
158// <li> Solve (as opposed to fit to a set of data), a set of equations
159// </ol>
160//
161// In addition to the basic Least Squares routines in the <src>LSQFit</src> and
162// <src>LSQaips</src> classes, this module contains also a set of direct
163// data fitters:
164// <ul>
165// <li> <src>Fit2D</src>
166// <li> <src>LinearFit</src>
167// <li> <src>LinearFitSVD</src>
168// <li> <src>NonLinearFit</src>
169// <li> <src>NonLinearFitLM</src>
170// </ul>
171// Furthermore class <src>LatticeFit</src> can do fitting on lattices.
172//
173// Note that the basic functions have <em>LSQ</em> in their title; the
174// one-step fitting functions <em>Fit</em>.
175//
176// The above fitting problems can usually be solved by directly
177// calling the <src>fit()</src> member function provided by one of the
178// <src>Fit</src> classes above, or by
179// gradually building the normal equation matrix and solving the
180// normal equations (<src>solve()</src>).
181//
182// A Distributed Object interface to the classes is available
183// (<src>DOfitting</src>) for use in the <I>Glish</I> <src>dfit</src>
184// object, available through the <src>fitting.g</src> script.
185//
186// </synopsis>
187//
188// <motivation>
189// This module was motivated by baseline subtraction/continuum fitting in the
190// first instance.
191// </motivation>
192//
193// <todo asof="2004/09/22">
194// <li> extend the Fit interface classes to cater for building the
195// normal equations in parts.
196// </todo>
197//
198// </module>
199//
200
201} //# NAMESPACE CASACORE - END
202
203#endif
204
205
this file contains all the compiler specific defines
Definition mainpage.dox:28