Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: fitter - Constructor Up: fitting - Module Previous: functionfitter.type - Function


fitter - Tool



Package utility
Module fitting


Postscript file available

fitting tool

Constructors
fitter Construct fitting tool
Functions
chi2 get the chi squared
constraint get missing rank constraint equations
covariance get the covariance matrix
deficiency get missing rank
done Remove the tool's resources
error get errors in unknowns
fitavg Get an average
fitpoly Solve polynomial equations
fitspoly Solve polynomial equationswith large x-range
fitted Test Levenberg-Marquardt loop
fitter Create a sub-tool
functional Solve a general fitting problem
getstate Obtain the state of the fitter
id identification of tool
init Initialize a fitting tool for use or re-use
linear Solve a linear fitting problem
rank get solution rank
reset Reset the tool to its initialized state
sd get standard deviation per unit weight
set (Re-)initialize selected fitting tool properties
solution get solution
stddev get mean error (standard deviation per observation)
type Obtain the type of the tool

A fitting tool has properties that can be set at creation; by the init method, by the set method and implicity by the use of the linear and functional methods. Properties are:



Example
A few basic examples: averaging a set of real numbers, and a set of complex numbers:
- include 'fitting.g'                                           # 1
T
- y := 0.1*1:5                                                  # 2
- f := dfs.compiled('p')                                        # 3
- dfit.linear(f,[],y);                                          # 4
T
- dfit.solution();                                              # 5
0.3 
- dfit.getstate()                                               # 6
[n=1, typ=0, colfac=1e-08, lmfac=0.001, type=real] 
- dfit.rank()                                                   # 7
1 
- dfit.sd()
0.158114 
- dfit.stddev()
0.158114 
- dfit.chi2()
0.1 
- dfit.covariance()                                             # 8
0.2 
- dfit.error()
0.0707107
- dfit.set(type='complex');                                     # 9
T 
- dfit.getstate()                
[n=1, typ=1, colfac=1e-08, lmfac=0.001, type=complex] 
- dfit.linear(dfs.compiled('p*x'), [1:6]*0 + 1, [1:6] + 1.5i*(1:6)) # 10
T 
- dfit.solution()                                               # 11
3.5+5.25i
# a one step option:
- dfit.linear(dfs.poly(), 1:5, 1:5); dfit.solution()            # 12
T 
3+0i
- dfit.set(type='real');                                        # 13
T 
- dfit.linear(dfs.poly(), 1:5, 1:5); dfit.solution()            # 14
T 
3
- dfit.set(type='complex')                                      #15
T

1.
Gives access to the fitting and creates the default fitting tool. It also includes the functionals tool.
2.
initialize the default fitter for 1 unknown (real by default)
3.
Create normal equations from 5 (simple) condition equations:
x = i
4.
Solve the normal equations
5.
Show the solution
6.
what is the fitter's state?
7.
the rank shows the number of dependencies. In this case there is no missing rank in the set of condition equations (i.e. they can be solved). The following functions show the information available after a solution. chi2 is the $ \chi^{2}_{}$; sd the standard deviation per observed point; mu the standard deviation per unit weight.
8.
the covariance and errors in the solved unknowns can be obtained. The errors are the covariance scaled with the standard deviation
9.
Make a complex fitter (re-use) with two simultaneous sets of equations
10.
Make normal equations (Note the multiple condition equations in call) Effectively the first argument (the coefficients of the parameter to be solved) is a vector of length 5, all elements value 1; the second is a matrix, with for each condition equation two values. The values are:
   - [1:5,2*(1:5)]+1i*(1:10)
   [1+1i 2+2i 3+3i 4+4i 5+5i 2+6i 4+7i 6+8i 8+9i 10+10i]
where alternate values belong to the same set of observables
11.
solve
12.
show solution (Note the indices)
13.
do a fit for functional polynomial of zeroth order

This example shows the general usage of the fitting tool for linear equations:

  • create and/or initialize a fitter
  • use one or more make() methods to create the normal equations
  • use fit() to solve the equations
  • use information methods to get the solution information
Some specialized fit methods are available to combine the above in one call.

The above, simple, example, it is assumed that the data will fit a zero degree polynomial (i.e. just an average). It is just as easy to fit through the same data a higher degree polynomial. Let us first make the observed values:

- y := [1:10]
The simple way to fit an average here is (note we are still in complex type mode, but easy to correct):
- dfit.fitavg(y)
T 
- dfit.solution()
5.5+0i 
- dfit.set(type='real')
T 
- dfit.fitavg(y)
T 
- dfit.solution()
5.5
Another way is to make use of a zero degree polynomial, specified as a = y:
- x:=array(1,10)
- dfit.fitpoly(0,x,y) 
T 
- dfit.solution()
5.5
What would a 2-degree polynomial through the data look like ( a + bx + cx2 = y):
- dfit.fitpoly(2,1:10,y)
T 
- dfit.solution()     
[0 1 0]

Non-linear fitting can be done in the same way; with slightly different calls for the full-blown case. For the generic case just replace the linear with functional, and a non-linear method will be used, using the Levenberg-Marquardt method.

The major difference is that the functional provided as model should have initial parameter estimates set.

Note that, of course, you can write your own non-linear solution by providing an initial parameter estimate in the functional to be fitted, use the linear method, and upfate the parameters until some criterium is met.

Tools
fitter fitting tool
functionfitter Tool to do simple fitting of numeric data

Constructors
fitter Construct fitting tool
Functions
chi2 get the chi squared
constraint get missing rank constraint equations
covariance get the covariance matrix
deficiency get missing rank
done Remove the tool's resources
error get errors in unknowns
fitavg Get an average
fitpoly Solve polynomial equations
fitspoly Solve polynomial equationswith large x-range
fitted Test Levenberg-Marquardt loop
fitter Create a sub-tool
functional Solve a general fitting problem
getstate Obtain the state of the fitter
id identification of tool
init Initialize a fitting tool for use or re-use
linear Solve a linear fitting problem
rank get solution rank
reset Reset the tool to its initialized state
sd get standard deviation per unit weight
set (Re-)initialize selected fitting tool properties
solution get solution
stddev get mean error (standard deviation per observation)
type Obtain the type of the tool




next up previous contents index
Next: fitter - Constructor Up: fitting - Module Previous: functionfitter.type - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15