02-10-2011 07:41 AM
Hi,
I am wondering about the convergence criterion of NI's fitting functions. Recently I have modified some of my model functions to return NaN if some function parameters are invalid (e.g. in case the parameters are not within a boundary, would lead to a dicision by zero,...)
In case of bad luck, this may result in a fit function consisting solely of NaNs. Surprisingly, NonLinearFitWithWeight returns without any complaint even in such cases - obviously it does not check if the calculated mean square error also is NaN...
Given that fact, what would be recommended: In the model functions, should I return a different value instead, i.e. Inf?
Right now, I use GoodnessOfFit and if sse etc. are NaN I know that the fit didn't succeed.
Thanks!
02-21-2011 06:51 AM
Hello again,
I have further investigated the issue and can add the following:
Let's assume two arrays of double values one or both containing a few NANs. These arrays can be plotted using PlotXYWaveform, which will simply ignore the NANs and plot the remaining data points. That's the behavior I expect.
Surprisingly, NonLinearFit behaves very different. If an array contains NANs, the fit routine returns after 1 iteration, with a squared error of NAN, but a status of 0.
Frankly, this is not the behavior I would expect. It should either do its job, i.e. do the fit ignoring the NAN data points, or return with an error.
02-23-2011 05:08 AM
Hello Wolfgang,
again, can you please post your code allowing us to reproduce the issue? Thank you.
Marco Brauner NIG
02-23-2011 05:40 AM
Hello Marco,
I have modified the example that shippes with CVI --- 'nlinfit' --- and am attaching the modified C source code. The first element of the data array is set to NAN - and the fit routine behaves as described above: no error, no fit. If you exchange the fit routines, i.e. use NonLinearFitWithWeight, you will also obtain the number of iteration, which is 1, even if you allow for 1000.
Thanks,
Leuk Oplast
03-03-2011 09:41 AM
Hi Marco,
have you been able to reproduce the issue?
03-10-2011 09:45 AM
Hi, sorry for replying so late.
I would need the whole CVI Project (inc. uir) for the test. Can you please post it?
regards
Marco Brauner NIG
03-10-2011 10:10 AM
Hi Marco,
thanks for the reply. I could post the project but you already have it : It comes with CVI: as mentioned earlier, I have used the sample nlinfit and only modified two or three lines in the C source code, which I had attached in the previous post. All the other files, include, UIR, cws, prj etc, are the original files from the sample.
03-21-2011 12:25 PM
Hi Wolfgang,
I have talked with an CVI developer about the issue, and he said that you would have to return an explicit error value from the function, in case
your input parameters turn out invalid, since all the floating point functions are working with NAN and also will return NAN values. If you do not
test the input against NAN-values, you won´t get any errors.
He said, you could return 1 = success , 0 = error, and set the actual values as output parameters via a pointer.
regards
Marco
03-22-2011 07:22 AM
Hi Marco,
thanks for looking into it! I understand that adding one parameter (status flag...) to the model function could solve the problem; however, for all of NI's NonLinearFit... routines the model function must be defined as:
double ModelFunct (double x, double a[], int ncoef);
So how could the suggestion be implemented?