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 paramater initialization
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bnahir

USA
Posts

Posted - 11/03/2006 :  10:47:13 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): Pro 7.5
Operating System: XP

Hopefully this is an easy question:
I am trying to automate a Gaussian fitting function using the nlsf package. This script was working, for the most part, until about an hour ago, when I suddently started receiving a runtime error saying the LabTalk command had failed. After a little error checking, I narrowed it down to the line
nlsf.execute("parainit");

It seems that all nlsf commands before that function fine but as soon as that line is called, the program generates the error. As I said, this function was working fine not too long ago and I didn't make any changes that should have affected that function call. Any suggestions?

My script (called by another function):
(cc_Rename is an in house, commonly used function)

double fitGauss(vector<int>& vCounts, int rangeBegin, int rangeEnd){
Dataset dsFreq;
string wksName="wksTemp";
string strData=wksName + "_b";

Worksheet wksTemp;
if (!wksTemp.Attach(wksName)){
if(wksTemp.Create()){
cc_Rename(wksTemp, wksName);
}
}
dsFreq.Attach(wksTemp.Columns(1));
dsFreq.Append(vCounts);

using nlsf = LabTalk.nlsf;
nlsf.init();
nlsf.cleanupfitdata();
nlsf.dataBegin=rangeBegin;
nlsf.dataEnd=rangeEnd;
nlsf.func$="Gauss";
nlsf.constr$="";
nlsf.fitData$=strData;
nlsf.execute("parainit");
out_str("Parameter initialization:");
out_double("y0=",nlsf.p1);
out_double("xc=",nlsf.p2);
out_double("w=",nlsf.p3);
out_double("A=",nlsf.p4);
nlsf.output(0);
nlsf.fit(100);
nlsf.end(13);

// wksTemp.Destroy();
out_double("Gaussian center (p2) = ",nlsf.p2);
return nlsf.p2;
}

Mike Buess

USA
3037 Posts

Posted - 11/03/2006 :  11:40:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Before losing any sleep over this problem I suggest you restart Origin. Sometimes strange things like this happen during extended Origin sessions, especially when programming is involved, and a restart is sometimes necessary to set things straight.

Mike Buess
Origin WebRing Member
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/03/2006 :  11:41:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi bnahir,

I took your function and did some simple modification as pasted below and tested and it worked fine on a gaussian dataset in my worksheet col B.

Not sure what is causing the error, and not easy to tell without specific data, range etc on which it fails.

Can you send your data and the actual error message that you got to tech support?

Easwar
OriginLab


void test(int rangeBegin, int rangeEnd)
{
Worksheet wks = Project.ActiveLayer();
string wksName = wks.GetPage().GetName();
string strData=wksName + "_b";


using nlsf = LabTalk.nlsf;
nlsf.init();
nlsf.cleanupfitdata();
nlsf.dataBegin=rangeBegin;
nlsf.dataEnd=rangeEnd;
nlsf.func$="Gauss";
nlsf.constr$="";
nlsf.fitData$=strData;
nlsf.execute("parainit");
out_str("Parameter initialization:");
out_double("y0=",nlsf.p1);
out_double("xc=",nlsf.p2);
out_double("w=",nlsf.p3);
out_double("A=",nlsf.p4);
nlsf.output(0);
nlsf.fit(100);
nlsf.end(13);

}


Go to Top of Page

bnahir

USA
Posts

Posted - 11/03/2006 :  3:18:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The gist of the error is that the parameters are not being initialized. The error text (in a pop up box) is:
Error! Parameter(s) y0, xc, w, A is(are) not properly initialized. Check their values.

This is where I am confused, because I was using the nlsf.execute("parainit") specifically for the parameter initialization...
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/03/2006 :  3:21:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi bnahir,

Does this happen with a particular dataset or any dataset? Does it happen with a dataset that used to fit fine with same code before? Did you try restart Origin? Do the parameters at that point have any value, or all are missing value?

It is hard to tell what is going on without having exact data and code to test with...

Easwar
OriginLab



Edited by - easwar on 11/03/2006 3:22:18 PM
Go to Top of Page

bnahir

USA
Posts

Posted - 11/06/2006 :  10:29:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi easwar,

Thanks for your help. I actually managed to figure out what my problem was (the data I'm working with is rather large and I didn't want to overwhelm our server..). I didn't realize that, in order to perform a nlsf fitting algorithm, I needed to supply both x and y values. I assumed that if only y values were used, the function would default to row numbers (or vector indices) as the x-values. Once I passed both vectors, it worked fine.

I do have one other question though. At the end, I'm trying to suppress all worksheet and graph outputs. I thought the way to do that is how I've written it, however, the function still creates both the nlsf data sheet and the fit window. Since method is called in an iterative loop, that generates a lot of wasted memory. Am I missing something regarding the output from the nslf?

Thanks
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 11/06/2006 :  11:14:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Not sure why but nlsf.output(0) must appear before nlsf.fitData$=strData.

Mike Buess
Origin WebRing Member
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