
Fit function with use of a structure

fernandes_edgar
I am a quite new Igor Pro user but already convinced by its high capabilities in data analysis.
At the present time, I am trying to fit a heavy function to data. My fit function has to use external wave as input data, therefore I am trying to write a structure based fit function.
I have already read the manual documentation about structures and fitting, but I still don't understand how structure based fit function works.
Here is the documentation code:
// The structure definition Structure expFitStruct Wave coefw // required coefficient wave Variable x // required X value input Variable x0 // constant EndStructure // The fitting function Function fitExpUsingStruct(s) : FitFunc Struct expFitStruct &s return s.coefw[0] + s.coefw[1]*exp(-(s.x-s.x0)/s.coefw[2]) End // The driver function that calls FuncFit: Function expStructFitDriver(pw, yw, xw, xOff) Wave pw // coefficient wave- pre-load it with initial guess Wave yw Wave xw Wave yw Variable xOff Variable doODR // An instance of the structure. We initialize the x0 constant only, // Igor (FuncFit) will initialize coefw and x as required. STRUCT expFitStruct fs fs.x0 = xOff // set the value of the X offset in the structure FuncFit fitExpUsingStruct, pw, yw /X=xw /D /STRC=fs // no history report for structure fit functions. We print our own // simple report here: print pw Wave W_sigma print W_sigma End
And here the execution code
Make/D/O/N=100 expData,expDataX expDataX = enoise(0.5)+100.5 expData = 1.5+2*exp(-(expDataX-100)/0.2) + gnoise(.05) Display expData vs expDataX ModifyGraph mode=3,marker=8 Make/D/O expStructCoefs = {1.5, 2, .2} expStructFitDriver(expStructCoefs, expData, expDataX, 100)
My question therefore is : How does fitExpUsingStruct know that "pw" is the parameter wave and "yw" the wave to fit? The structure has never be initialized, therefore there is no link between "fs.coeff" and "pw", nor "fs.x" and "xw".
I must be missing some fundamental key, any explanation would be appreciated.
This problem blocks me because my fit function is not analytic and I don't know how to deal with the data in order to get it work.
Tanks!!
You do not see the Y data wave, and the X wave passed to your fit function is not the same as the X data you provide to the FuncFit command. The coefficient wave may or may not be the original coefficient wave from your driver function. Since FuncFit will fill in the first three members of your structure, you do not set them yourself in the driver function. Your driver must fill in any additional members. If you are using the structure to pass some auxiliary wave to the fit function, your driver must set that wave in the structure before calling FuncFit.
The job your fit function must perform is to fill up the Y wave in the structure with one model value for each X value in the X wave in the structure.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 10, 2014 at 09:30 am - Permalink
Protra
October 13, 2014 at 01:21 am - Permalink