Author |
Topic  |
|
Nai
Canada
Posts |
Posted - 05/24/2005 : 3:25:46 PM
|
Origin Version = 7.5 SR0 Operating System: win 2000
Is there a method to suppress and/or check for NLSF errors during peak fitting operations in origin C so that the appropriate action may be coded for?
I am currently trying to fit multiple gaussians to numerous datasets in an autonomous project, and hence do not want to have to hit OK each time one of the initial mean parameters (e.g. xc1) isn't close enough.
Thanks |
|
Mike Buess
USA
3037 Posts |
Posted - 05/24/2005 : 4:08:00 PM
|
You can try nlsf.msgprompt=0 but I'm not sure that will suppress all of the error messages you are getting. If that isn't enough you can look into OC's error handling capabilities...
Programming Guide > Programming in Origin C > Error and Exception Handling
Mike Buess Origin WebRing Member |
 |
|
Nai
Canada
Posts |
Posted - 05/24/2005 : 4:56:02 PM
|
I cannot seem to find the "Error and Exception Handling" help document in Programming Guide > Programming in Origin C > Error and Exception Handling.
Could it be that I am using OriginPro 7.5 SR0 ? |
 |
|
easwar
USA
1965 Posts |
Posted - 05/24/2005 : 5:32:43 PM
|
Hi Nai,
If I understand correctly, you want to know programmatically if your fit has converged/succeeded or not.
You can use code such as pasted below to do this.
For example, first import the sample data file gaussian.dat and then call this function with the data name and the function name = "gauss". You will see that the fit converges and you get the correct message from the code.
Now import the file expdecay.dat and call the code with the col B data name and the same function "gauss". You will see that the fit does not converge and you get the message from the code that it did not.
You can try the GUI with the expdecay data and the gauss function and you will see that repeated clicking on the 100 Iter button results in no convergence because the data and the function do not match.
Typically if the function and data match, 1 or 2 clicks on the 100 Iter button is all it takes. Then with further clicks, the fitter will at most do only 1 more iteration. So in the code I am checking if the number of iterations performed is less than 2, and if so it is safe to assume that the fit did converge. You should confirm this independently with a few of your datasets and your function.
Easwar OriginLab
void fit_check_error(string strData, string strFunc) { // Point to NLSF object using nlsf = LabTalk.nlsf; // Reset the object nlsf.Init(); // Turn off error message dialogs nlsf.MsgPrompt=0; // Assign function name and dataset names nlsf.func$ = strFunc; nlsf.FitData$ = strData; // Execute para init code if the function has such code nlsf.Execute("parainit");
// Or set para values yourselves // nlsf.p1 = 10; // nlsf.p2 = 20; // etc..
// Try fitting the data, by simulating up to 5 clicks of the "100 Iter" button for(int ii = 0; ii < 5; ii++) { nlsf.IterateEx(100); // If fitter does one iter or zero iters, fit has converged if( nlsf.nIter < 2 ) break; } // If nIter never reached 0 or 1, then fit has not converged in "5 clicks" if( 5 == ii ) { out_str("Fit did not converge..."); // Do whatever it is that you want to do here, // such as changing initialization and trying again etc } else { out_str("Fit converged"); nlsf.End(); } }
|
 |
|
Nai
Canada
Posts |
Posted - 05/25/2005 : 09:32:46 AM
|
Thanks easwar, I will try to implement the solution as soon as I can!
Just to be clear, what does nlsf.iterateEx() do, since I only found documented information about nlsf.iterate().
Thanks
|
 |
|
Nai
Canada
Posts |
Posted - 05/25/2005 : 09:52:05 AM
|
I tried a quick implementation of Easwar's code, but it does not seem to help for my multiple Gaussian fitting problem.
What I am trying to do is fit multiple 'histogram worksheets' created from multiple experiment trials with a double Gaussian, extract the mean and width params for each graph, and then export each fitted graph to a file. This process continues over many 'worksheets' until the EOF is reached in the input file.
My problem is that to speed things up, I am only guessing the xc1 and xc2 params once in the beginning, and due to problems with some of the experimental data (e.g. low frequency counts that are not gaussian), these initial peaks are not always close and hence originpro throws a 'Error 28036. Try setting parameter 'xc1' as fixed' (or xc2). Since I am dealing with a lot of independent trials, I want the program just to run independently without me having to sit in front of it and hit 'ok' every time such an error pops up. It would also be beneficial if I could create a log for the errors to be viewed later, but currently I just want to suppress them.
Thanks |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 05/25/2005 : 10:02:02 AM
|
Have you tried nlsf.msgprompt=0?
Mike Buess Origin WebRing Member |
 |
|
easwar
USA
1965 Posts |
Posted - 05/25/2005 : 10:02:28 AM
|
Hi Nai,
Please send a few of your datasets/files along with your fitting code to tech support so that we can take a look. Please mention this thread in your e-mail.
Easwar OriginLab
|
 |
|
Nai
Canada
Posts |
Posted - 05/25/2005 : 10:24:49 AM
|
The files were sent.
Mike, I did try msgPrompt=0 and it didn't seem to have any effect. |
 |
|
easwar
USA
1965 Posts |
Posted - 05/25/2005 : 10:57:18 AM
|
Hi Nai,
We got the files and took a quick look - we see that you issue the nlsf.msgPrompt = 0 before the nlsf.Init command - move the msgPrompt command to be after the Init command and that should suppress the messages.
If you run into further problems, we can continue to look at your C file.
Easwar OriginLab
|
 |
|
Laurie
USA
404 Posts |
Posted - 05/25/2005 : 11:11:10 AM
|
Hi Nai,
quote: Just to be clear, what does nlsf.iterateEx() do, since I only found documented information about nlsf.iterate().
What's the difference between NLSF.IterateEx(100) and NLSF.Iterate(100)?
Let's look at this code:
NLSF.Init(); // initialize fitter NLSF.Func$ = Exponential; NLSF.FitData$ = %C; NLSF.Execute(parainit); NLSF.Iterate(100);
If you were to have a graph active and then run the above code from the Script Window, you would not see the fit curve drawn on the graph. In other words, you only see the fit curve drawn in the end and controlled by NLSF.End( ). Remember that NLSF.End(13) will not show fit curve, but NLSF.End(12) will.
IterateEx mimics the behavior from the GUI. As you click the Iter. button in the fitter GUI, you'll see a temporary Yfit curve drawn on the graph. So now if you were to run the following:
NLSF.Init(); // initialize fitter NLSF.Func$ = Exponential; NLSF.FitData$ = %C; NLSF.Execute(parainit); NLSF.IterateEx(100);
you would see the red fit curve in the graph; it's just temporary and called yfit. When you then run nlsf.end( ) this will control the behavior in the end.
So the point is that you can use either one, but I'd probably stick with nlsf.iterate, since you're fitting from script where you don't need to mimic GUI behavior.
Laurie
OriginLab Technical Support |
 |
|
Nai
Canada
Posts |
Posted - 05/25/2005 : 11:53:55 AM
|
Thanks for clearing that up Laurie, Now, if I can only figure out this error suppression problem :P |
 |
|
easwar
USA
1965 Posts |
Posted - 05/25/2005 : 11:59:51 AM
|
Hi Nai,
So changing the order of commands to: nlsf.Init(); nlsf.msgPrompt=0;
did not work?
Easwar OriginLab
|
 |
|
Nai
Canada
Posts |
Posted - 05/25/2005 : 12:13:14 PM
|
Easwar, Thanks a lot!
The mistake was in my order of execution!
However, is there a way to output these errors into the results window or a text file? |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 05/25/2005 : 12:51:18 PM
|
nlsf.err gives you the code of the last error that has occurred. I imagine it's reset by nlsf.init() so you could print it to the script window by adding nlsf.err=; after each fit...
nlsf.iterate(100); nlsf.err=;
Mike Buess Origin WebRing Member |
 |
|
easwar
USA
1965 Posts |
Posted - 05/25/2005 : 1:44:03 PM
|
Hi Nai,
Currently the nlsf.err property only works from the GUI such as when an error dialog pops up, it shows the error code. When programmatically accessed, this property gets reset internally at the end of the fit and if you try to read it you will always get zero.
So for now what you could do is to check if the convergence occured by testing the number of iterations performed, following the logic in the code segment posted before, and then for your error messages you could then print out for which dataset convergence did not happen - but you cannot print out what exactly the error number was.
Easwar OriginLab
|
 |
|
Nai
Canada
Posts |
Posted - 05/26/2005 : 09:13:25 AM
|
Thanks, I guess that's all I can do then. |
 |
|
beharris
Australia
Posts |
Posted - 02/26/2006 : 06:51:50 AM
|
Origin Version = 7.5 SR6 Operating System: winxp
Hi,
I know this thread is a little old, but I was just wondering if there was any update on this problem.
Like Nai I was wondering about logging the error code, or at least setting a "flag" if the error appeared. I wanted to differentiate this error code ( 'Error 28036. Try setting parameter 'xc1' as fixed' (or xc2)) from a "failure to converge" as they have different meaning for me.
Many thanks
Ben |
 |
|
Laurie
USA
404 Posts |
Posted - 02/27/2006 : 10:56:41 AM
|
Hi Ben,
Thank you for bringing this up again. With the SR6 Service Release for Origin 7.5, a new LabTalk property nlsf.iteroutcome has been introduced. It is similar to nlsf.err, except that it keeps its value regardless of success or failure.
To determine if the fit converged, you want to check whether nlsf.iteroutcome returns either 28028 or 28044.
28028 means that despite change parameter values, chi-square could not be reduced. This usually means that that it is already at a minimum, i.e. that parameter values are a good fit.
28044 means that tolerance has been reached, i.e. that the relative reduction of chi-square between two consecutive iterations is below the tolerance.
For example:
void fit(string strData, string strFunc) { using nlsf = LabTalk.nlsf; nlsf.Init(); nlsf.func$ = strFunc; nlsf.FitData$ = strData; nlsf.Execute("parainit"); double dErr; for(int ii = 0; ii < 20; ii++) { nlsf.IterateEx(100); dErr = nlsf.Iteroutcome; printf("%d --> %f\n", ii, dErr); if( (28028 == dErr) || (28044 == dErr) ) break; } if( 20 == ii ) { printf("Fit did not converge after 20 rounds of iteration - must be bad data/model\n"); } else { printf("Fit converged!\n"); nlsf.End(); } }
OriginLab Technical Support |
 |
|
beharris
Australia
Posts |
Posted - 02/27/2006 : 11:51:45 PM
|
Hi Laurie,
The error message that I wanted to suppress (but log) is
---->"Error 28036. Try setting parameter... as fixed."
Would I be right in assuming that this is the 28044 error code? Or is it perhaps something different?
Many thanks
Ben |
 |
|
Laurie
USA
404 Posts |
Posted - 02/28/2006 : 12:31:44 PM
|
Hi Ben,
For example, if I get the "Error 28036 - Try setting parameter xc as fixed" message box in the GUI, and then at this very instance, if I go to script window and check nlsf.iteroutcome, it is 28044 and not 28036. However, once i click OK on the dialog and check nlsf.iteroutcome, it is 28036, so the property was just not set yet when the dialog was up.
As discussed above in earlier posts, use nlsf.msgPrompt=0; to supress the error messages. You can then check nlsf.iteroutcome for the value of 28036.
Laurie
OriginLab Technical Support |
 |
|
tony_lincoln
USA
Posts |
Posted - 09/08/2006 : 8:57:12 PM
|
In the sentence, "nlsf.FitData$ = strData", what does strData mean? Is it the full name of the txt file, like "C:\data.txt", and inside this file, there are two columns, one is x and one is y? Why is there always error in this sentence when I tried to do the curve fitting? Thanks. Tony |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/09/2006 : 12:50:21 AM
|
Tony,
NLSF knows nothing about data files but works only on data in Origin wks columns. In general, strData will be in the form of wksName_colName. See my reply to your other topic for details.
Mike Buess Origin WebRing Member |
 |
|
|
Topic  |
|