The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 repeat NLSF upon user request w/o restarting code
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

obauer

Germany
15 Posts

Posted - 06/19/2009 :  12:19:57 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8 SR4
Operating System: Windows XP

Hello erveryone!

I am facing the following issue: I have written an Origin C code which performs two successive NLSF fits to two differnet datasets where fit parameters from the first fit are used as fixed parameters for the second fit. In principle the code runs smoothly.

Now I would like to have the option to repeat the second fit with different parameters if I am not contend with the fit result WITHOUT having to fit the first dataset again (its fit takes about 5 minutes due to an included convolution...). I am thinking of having something like an input box popping up after the second fit has been done; the user is requested to decide whether he would like to finish the program now or whether he would like to go back to the point in the code where the second fit starts.

Does anyone know how to realise that?

In my case there is a further limitation: that is I already have included a GetNBox in the code - and as far as I know you can´t open a second one in the same routine. Is that correct? Or can I have a second GetNBox?

In case I would have to split my routine in two parts (one for each NLSF fit) to realise the user request option: How could I automatically pass on parameters from Part 1 to Part 2?

I really appreciate any comment since I don´t have a clue how to implement this user request option. If you have an idea how to solve the issue, please share it with me. Thank you so much for your help!

best regards,
Oliver

Iris_Bai

China
Posts

Posted - 06/22/2009 :  06:04:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I tried pass NLFit& to one function as input and output variable, but when pass this NLFit object as input to another funciton, seems that the result in NLFit object all are missing. So cannot pass NLFit& here.

Origin C support a better NLFit class named NLFitSession. More document and samples about this class please take a look on:
Class reference:
http://ocwiki.originlab.com/index.php?title=Category:NLFitSession_%28class%29
Sample codes:
http://ocwiki.originlab.com/index.php?title=Category:Using_NLFitSession

The following process shows how to use GetN dialog to ask continue part 2 fit or quit.
1. Copy all example codes from the following linking:
http://ocwiki.originlab.com/index.php?title=Category:NLFitSession_%28class%29
and change function prototype to bool NLFitSession_Fit_ex(NLFitSession& FitSession).

2. Add the following codes to call part 1 do fit and used the fitted parameters in part 2 fit:

#include <..\originlab\NLFitSession.h>
void part2_fit(NLFitSession& nlfit)
{	
	vector vParamValues, vErrors;
	nlfit.GetFitResultsParams(vParamValues, vErrors);    

    out_str("In part2_fit function");
    for(int nn=0; nn<vParamValues.GetSize(); nn++)
	{
		printf("P%d = %f\n", nn+1, vParamValues[nn]); // output the parameter values
		
		nlfit.SetParamFix(nn, true); // to set parameters as fixed
	}	
}

void main_func()
{
	NLFitSession nlfit;
	NLFitSession_Fit_ex(nlfit); // do fit for part 1, all results still keep in NLNLFitSessionFit object after running
	
	GETN_BOX(tr)
	GETN_CHECK(IsContinue, "Is Continue?", 1)
	
	while( GetNBox(tr) )// return true if click OK button
	{
		part2_fit(nlfit);
	}	
}


Iris

Edited by - Iris_Bai on 06/22/2009 06:29:14 AM
Go to Top of Page

obauer

Germany
15 Posts

Posted - 06/23/2009 :  03:07:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Iris!

Thank you so much for your efforts and your detailed answer! It looks like your code is what I was looking for...

Before I seriously think about swapping from NLSF to NLFit (and changing all my running code) I would like to know explicitly what the advantages of NLFit are as compared to NLSF? Is there any documentation on this? The other point which keeps me sticking to NLSF is that NLSF topics have been - by far - more intensely discussed in this forum. So NLfit almost feels somewhat undiscovered to me...

Could you please give me some more details on NLFit: What are the improvements in comparison with NLSF?

Thanks again for your time.

Best regards,
Oliver
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 06/23/2009 :  08:40:10 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
NLSF is the old fitter before Origin 8. We keep it around for backward compatibility reason only. NLSF has no Origin C support, as it is only a LabTalk object. You can use it in Origin C as a LabTalk extension only.

NLFit on the other hand (NLFitSession), is the new fitter in Origin 8. This is a totally rewritten fitter which is what you see from the menu with all the new GUI. This new fitter handles the fitting process with a copy of the data during the iteration so it is faster, since the older NLSF fitter directly access the worksheet during that same minimization process.

I can name the following two main reasons to switch to the new NLFit,

1. it is what is used in Origin 8, so all the bug fixing will be up to date as many more people use the GUI version and the Origin C version is the same engine.

2. It was written to be fully exposed to programming from Origin C. The NLFitSession class is an Origin C class. There is an even lower level class that you can use, see the ONLSF.h file, but we recommend that you use the NLFitSession level as that is the same class we use in the GUI dialog as well, and much easier to program.

To see the speed of this new fitter, try this link

http://ocwiki.originlab.com/index.php?title=OriginC:Fit_Multiple_XY_Data_in_a_loop

It shows that you can fit 100 datasets in a couple of sec.

The reason NLFit is hidden is because we have not really documented this area yet. NLSF was all through out because it was from Origin 7.5.

You can start from this page and we will add more documentation

http://ocwiki.originlab.com/index.php?title=Category:Fitting

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000