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
 NLSF para init-looking 4 best user friendly sol'n
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

srosekra

USA
Posts

Posted - 08/26/2005 :  8:59:14 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
The Simple Question:

Can you disable/enable the Automatic Parameter Initialization from OriginC?

Tough Question:

I have a graph with multiple peaks. I am writing a program that will fit one specific peak that is specified by the user for multiple worksheets (alot of them). I have to do it a peak at a time because of the data spikes that I have in the graphs, so mult peak fit is not a solution to this problem. I have been able to fit the largest peak using the NLSF.execute(parainit) to get the initial parameters. I want to use this for the other peaks so I used the following code
//anything commented was left in the code and also commented out
//in a variety of orders and still no success.
using NLSF = LabTalk.NLSF;
NLSF.Init();
//NLSF.cleanupfitdata();
NLSF.Func$ = "Lorentz";
NLSF.numReplica = 0;
NLSF.dataBegin = 646;
NLSF.dataEnd = 754;
//NLSF.xmode = 5; //=1; //=0;
//NLSF.xBegin = 646;
//NLSF.xEnd = 754;
NLSF.v1 = 1;
NLSF.v2 = 1;
NLSF.v3 = 1;
NLSF.v2 = 1;
NLSF.FitData$ = "junkd10_B";
//NLSF.Execute("parainit");
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Iterate(100);
//NLSF.IterateEx(100);
//NLSF.Fit(100);

Now I did Isolate the problem, and that is with the parameter initialization. I was using the NLSF.execute(parainit), and I debugged it into the _NLSFparam.fit file and found that the xycurve (when fit from the menu with Arrow Data Selectors), that it contained the value: _Temp1/_Temp2(754:646-753) or something to that nature. But when done from my OriginC program gave the full range [_Temp1/_Temp2(1024:1-1023)]. And hence game me the parameter for the largest peak! This happened even though I included the NLSF.dataBegin/End commands.
Is there a way around this using NLSF commands that would give a data range to the parameter initializer?
If I have to, Could I call the NLSF.fit file myself and feed it my own Curve?
Least desired possiblility:I was able to do it by plotting but I am sure it will slow the program too much, will it work with a _TempWkst with only the data range that I want plotted? I also have another solution that is working but will cause future problems and I would like to find the best user friendly solution that I can.

Urgent need of help!
Thankyou

Sean Rosekrans

Origin Version (Select Help-->About Origin): 7.5 Pro
Operating System: XP

easwar

USA
1965 Posts

Posted - 08/29/2005 :  1:56:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Sean Rosekrans,

quote:

The Simple Question:

Can you disable/enable the Automatic Parameter Initialization from OriginC?




Yes, see this post for example:
http://www.originlab.com/forum/topic.asp?TOPIC_ID=4057

As for the rest:

nlsf.dataBegin and dataEnd should work fine. These properties should set the fit dataset to only the subset of data that you want to fit. The parameter initialization then works only on this subset that you select - in other words the initialization is sensitive to your subset selection of the data.

I did the following to test this:
1> imported multpeaks.dat file from the \Samples\Data subfolder
Column B will then have data that is composed of three lorentzian peaks, one in subset of rows 1-24, next in 25-60 and thrid in 61-100
2> compiled and ran the code pasted below which then selects each subset, performs proper initialization, and then fits each subset separately

Easwar
OriginLab


void fit_data_in_segments()
{
using NLSF = LabTalk.NLSF;
NLSF.Init();
NLSF.Func$ = "Lorentz";
NLSF.FitData$ = "Multpeaks_B";

// fit first peak
NLSF.dataBegin = 1;
NLSF.dataEnd = 24;
NLSF.Execute("parainit");
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Fit(1);

// fit second peak
NLSF.dataBegin = 25;
NLSF.dataEnd = 60;
NLSF.Execute("parainit");
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Fit(1);

// fit third peak
NLSF.dataBegin = 61;
NLSF.dataEnd = 100;
NLSF.Execute("parainit");
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Fit(1);

}



Go to Top of Page

easwar

USA
1965 Posts

Posted - 08/30/2005 :  2:50:33 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Sean Rosekrans,

My apologies...I went back and debugged the code and I see that indeed para init is passed the entire curve, disregarding the settings of nlsf.databegin and dataend. This is a bug. And in my case the fit worked out fine because even thought the init parameters were "way off", the fitter found the optimal parameters for each section because the minimization was working only with the correct subset of the data and the data and the function were a very good match etc.

For now the workaround is for you to use the mks1 and mks2 LabTalk variables which set the limit on what part of the data should the analysis operate on.

So the code example I posted would change to:

Easwar
OriginLab


void fit_data_in_segments()
{
using NLSF = LabTalk.NLSF;
NLSF.Init();
NLSF.Func$ = "Lorentz";
NLSF.FitData$ = "Multpeaks_B";

string str;

// fit first peak
str.Format("mks1 = %d;mks2 = %d;",1, 24);
LT_execute(str);
// NLSF.dataBegin = 1;
// NLSF.dataEnd = 24;
NLSF.Execute("parainit");
printf("%f %f %f %f\n", NLSF.p1, NLSF.p2, NLSF.p3, NLSF.p4);
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Fit(1);

// fit second peak
str.Format("mks1 = %d;mks2 = %d;",25, 60);
LT_execute(str);
// NLSF.dataBegin = 25;
// NLSF.dataEnd = 60;
NLSF.Execute("parainit");
printf("%f %f %f %f\n", NLSF.p1, NLSF.p2, NLSF.p3, NLSF.p4);
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Fit(1);

// fit third peak
str.Format("mks1 = %d;mks2 = %d;",61, 100);
LT_execute(str);
// NLSF.dataBegin = 61;
// NLSF.dataEnd = 100;
NLSF.Execute("parainit");
printf("%f %f %f %f\n", NLSF.p1, NLSF.p2, NLSF.p3, NLSF.p4);
NLSF.Iterate(100);
NLSF.Iterate(100);
NLSF.Fit(1);
}








Edited by - easwar on 08/30/2005 2:58:44 PM
Go to Top of Page

srosekra

USA
Posts

Posted - 09/09/2005 :  6:15:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This is what I did with no success...

using NLSF = LabTalk.NLSF;
...
//NLSF.begin();
NLSF.Init(); //initializes the object.
//NLSF.cleanupfitdata();
string funcname = "RamanLorentz";
//RamanLorentz is the Lorentz function I saved without auto paraminit
NLSF.Func$ = funcname;
NLSF.msgPrompt = 0;
NLSF.numReplica = 0;
NLSF.wType=0;
NLSF.w$="";
NLSF.chisqrerr=1;
cnumstr.Format( "%s%d_B", grname, v ); //complete curr wkst name.
NLSF.FitData$ = cnumstr;
tmpstr1.Format("mks1 = %d;mks2 = %d;",peak1,peak2);
LT_execute( tmpstr1 );
NLSF.dataBegin = peak1;//Data Range beginning ex:646 -> is the Row #. NLSF.dataEnd = peak2;//Data Range end
NLSF.Execute("parainit");
printf("wavelength - %d", NLSF.p2);

for (int ii = 0; ii <= marker; ii++)
{
v = g_start + ii; //next wkst #.
cnumstr.Format( "%s%d_B", grname, v ); //complete curr wkst name.
NLSF.FitData$ = cnumstr;//gives object the wkst name that will be fit.
NLSF.Iterate(100);//100 iterations
//These are the parameters that we are interested in.
dd1[ii] = NLSF.p1; //y0
dd2[ii] = NLSF.p2; //xc -> definite need
dd3[ii] = NLSF.p3; //w -> definite need
dd4[ii] = NLSF.p4; //A
Worksheet des("NLSF1"); //create obj so NFLS1 wkst is found & destroy
des.Destroy(); //deletes worksheet from Project Explorer
}
...
Idea was to do initial parameterization once to fit first graph and then use the parameter of the first graph for the next and so on, since the values are only slightly shifted.

What's different?
I can send you a graph of the data that I am attempting to fit.

Thankyou
Go to Top of Page

easwar

USA
1965 Posts

Posted - 09/10/2005 :  2:27:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

From earlier posts my understanding was that you wanted to fit multiple peaks within one dataset. Now it looks like you are trying to fit part of a peak from many datasets? Also not sure why you are setting both nlsf.begin, nlsf.end as well as mks1 and mks2 etc.

Please send your OPJ and your FDF and the OC code and a clear explanation of what you want to fit to tech support and we can follow up with you via e-mail.

Thanks,

Easwar
OriginLab

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