Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
Package | utility | |
Module | fitting | |
Tool | functionfitter |
x | in | The coordinate values | |
Allowed: | Numeric vector | ||
y | in | The ordinate values | |
Allowed: | Numeric vector | ||
yerr | in | The errors in the ordinate values | |
Allowed: | Numeric vector | ||
Default: | None used | ||
mask | in | The mask | |
Allowed: | Boolean vector | ||
Default: | All good | ||
xunit | in | The unit of the x-data | |
Allowed: | Unit string | ||
Default: | 'm' |
This function sets the data that you wish to fit. You must give the x and y data. You can optionally give the errors in these. You can optionally give a mask. If you don't give a mask, all the data are assumed to be good (T).
You need to be aware of how the coordinate values (x-data) are packed if the dimensionality of the function you wish to fit (and the coordinates) is greater than 1. The coordinates are stored as n-tuplets in a 1-D vector. For example, if you are fitting a 2-D function, then the x vector would consist of n 2-tuplets, where n is the length of the ordinate vector. The order would be ( [x1,x2]1, [x1,x2]2, [x1,x2]3... ). This all means that if the dimensionality of the function you are fitting is dim, and the length of the y vector is n, then the length of nx must be dim*n. The only exception to this is if the function has 0 dimensions (e.g. a constant). In this case, you should really specify an empty x vector, but Functionfitter handles this for you internally so it doesn't matter.
If and when you plot the data, a Tabular coordsys tool is made internally for you. This maps pixel index to the world x values that you specified with the x vector. The world units are given by the xunit variable, which defaults, not very helpfully perhaps, to metres. You can replace this Tabular Coordinate System if you want with another via the setcoordsys function.
- include 'functionfitter.g' - ff := functionfitter() - x := 1:10 - y := 3 + 2*x - ff.setdata (x,y)
- include 'functionals.g' # Load basic functionals module - n := 50 # Size of arrays - # Create a Gaussian2D functional with parameters - p := [1.0, n/2, n/2, n/3, 0.5, 30*pi/180] # Amp, posx, posy, major, ratio, pa - g2d := dfs.gaussian2d(p) - - # Generate coordinate and value arrays - x := []; # X packed as tuplet coordinate vectors in a 1-D vector - z := []; # i.e. like ( [i_1,j_1], [i_2,j_2], [i_3,j_3] ) # - k := 1; - l := 1; - for (j in 1:n) { for (i in 1:n) { x[l] := i; # Fill x x[l+1] := j; l +:= 2; # z[k] := g2d.f([i,j]) # Fill function k +:= 1 } } # - include 'functionfitter.g' # Create fitter - dff.setfunction(g2d) # Set functional - dff.setdata (x, z) # Set data - dff.setparameters(0.8*p) # Set initial model - dff.fit(F) # Do non-linear fit - print 'Expected = ', p # True result - print 'Solution = ', dff.getsolution() # Fitted result