Advanced fitting routine
Hi,
This will likely be a long post, hopefully I am able to get assistance and hopefully this serves as assistance for any other developers using Igor in the future. My apologies if there exist forum posts that pertain to my issue, but I find it doubtful that a complete solution exists.
I am developing a program in Igor that will be used to fit different types of optical data: Transmission, Reflectance, etc. There are numerous models used to fit this data, all of which are used to create what is call the Dielectric Function of a material, from which we can extract the rest of the optical data. In general, models take an undefined number of oscillators, and each of these oscillators has associated with it some number of parameters. For one model, an oscillator has 3 parameters: a resonant frequency, a driving frequency and a damping coefficient; another model has 4 parameters, and there exist many other models with a varying number of parameters. In general, to calculate the dielectric function for one of the models, you will do something like this:
Wave parameters // coefficient wave
int i // loop index
Variable A, B, C, dielectricFunc // oscillator parameters and dielectric function wave
dielectricFunc = 0
for(i=0; i<numOscillators; i+=1)
A = parameters[0]
B = parameters[1]
C = parameters[2]
dielectricFunc = dielectricFunc + A * B * C
endfor
As I have mentioned, there are numerous models that we might use, and we want to sum all of them together. We may in one instance not use all of the models but only a few, and each will have a varying number of oscillators in it. I am using a panel filled with SetVariables, and each of these will contain the parameters. I would, in theory, like to keep each oscillator separately grouped, and be able to identify it with the other parameters associated with that oscillator (that is, I want the A, B and C parameters for any given oscillator to move together). One way to do this would be to make where N=(#,3), and store the parameters in each of the columns, but when it comes to fitting the wave must be condensed into one dimension. When fitting that 1-D coefficient wave, my only thought is that once I encounter a parameter from a given model, I grab the next two and assume they are the other parameters from said model, and perform my computation. Then the problem is: how do I identify what model a parameter is from. Certainly, I could make a text wave at some point that just stores all of the information of each of the parameters, and as of now that is the plan, but my hope is that someone else will be able to suggest a more efficient way. I think that information about a given value should have an exact tie to that value: setting Dim Labels in a wave is a nice way to do that, but I see people use structure fitting functions as well, and I was wondering if those would be any better for my case? Certainly I should be able to get the job done, but I would like the code to be as readable as possible because in the future other researchers may wish to add functions to it, and it should not be overly complex. In addition, I would like to keep my code as compact as possible in order to avoid bugs. Please let me know if you have any suggestions, they are greatly appreciated.
Well, a Structure fit function is designed exactly to provide a way to pass along information other than the standard information that FuncFit knows about. So that would be one way to do it. It has certain drawbacks: it takes a higher level of Igor programming knowledge and it can't be run from the command line, you have to write a driver function that creates an instance of your structure and then calls FuncFit.
Another way to do this would be a wave containing additional information that your fit function looks up when it runs. It's easier to program, and can be run from the command line. It is also error-prone because you have to remember to keep that wave updated with any new information for the fit you're running at the moment. So if you're up to it, I would use a structure fit function in preference.
August 2, 2018 at 05:02 pm - Permalink