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: About general operation failure.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bluecourse

China
Posts

Posted - 05/31/2007 :  08:47:58 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin 7.5 PRO):
Operating System:XP
Hi, Mike
I want to fit a large data set at regular intervals by using 'for' loop. For example: Data range: 1,2,3,4,5,6 ... ... 120000. Fitting data set at 20 interval, Fit1: data[1-20], Fit2:data[21-40], Fit3:data[41-60]... ...
But when fitting, it run very long time and can't finish. The fitting function is very simple, so I think it's someting wrong. Then I break program by using 'ESC' key.it produce error:
*****Origin C Function Runtime Error, general operation failur*****. The error position point to the fitting function. The function is definied in Advanced Fitting Tool menu, it's no problem. This case happened even if I use other user definied function. I doubt that when I recall NLSF operation in the OC code, the fitting function can not get valid data. Can you give me some advices. Sorry for troubling you these days, thanks a lot.
The following is my function,it's definied by Advanced Fitting Tool menu.

void _nlsfWeightFitting3(
// Fit Parameter(s):
double w1, double w2, double w3,
// Independent Variable(s):
double fr1, double fg1, double fb1, double fr2, double fg2, double fb2, double fr3,
double fg3, double fb3, double Ir, double Ig, double Ib,
// Dependent Variable(s):
double& Rm, double& Gm, double& Bm)
{ <-----------*****I clicked the error info,then it point to here.*****
// Beginning of editable part
Rm=(fr1*w1 + fr2*w2 + fr3*w3)*Ir;
Gm=(fg1*w1 + fg2*w2 + fg3*w3)*Ig;
Bm=(fb1*w1 + fb2*w2 + fb3*w3)*Ib;
// End of editable part
}


The following is my OC code for fitting.

void WeightFitting3(int interval)
{
//Define Data Type.
string str;
int lsi, lsj;
int length1,length2;

//Define Process.
// Declare worksheet, data curve and error dataset and check validity
Worksheet wks = Project.ActiveLayer();
wks.GetRange(length1,length2);

//Get initial weight.
Dataset weight1(wks, 12);
Dataset weight2(wks, 13);
Dataset weight3(wks, 14);

//NLSF.
using NLSF = LabTalk.NLSF;
NLSF.begin();
NLSF.cleanUpFitData();
NLSF.msgPrompt=0;
NLSF.Output(0);
NLSF.Func$ = "WeightFitting3";

NLSF.x1$ = wks.Columns(18).GetDatasetName();
NLSF.x2$ = wks.Columns(19).GetDatasetName();
NLSF.x3$ = wks.Columns(20).GetDatasetName();
NLSF.x4$ = wks.Columns(21).GetDatasetName();
NLSF.x5$ = wks.Columns(22).GetDatasetName();
NLSF.x6$ = wks.Columns(23).GetDatasetName();
NLSF.x7$ = wks.Columns(24).GetDatasetName();
NLSF.x8$ = wks.Columns(25).GetDatasetName();
NLSF.x9$ = wks.Columns(26).GetDatasetName();
NLSF.x10$ = wks.Columns(15).GetDatasetName();
NLSF.x11$ = wks.Columns(16).GetDatasetName();
NLSF.x12$ = wks.Columns(17).GetDatasetName();
NLSF.y1$ = wks.Columns(0).GetDatasetName();
NLSF.y2$ = wks.Columns(1).GetDatasetName();
NLSF.y3$ = wks.Columns(2).GetDatasetName();

//Define constriant.
NLSF.constr$ = "0<w1<1";
NLSF.constr$ = "0<w2<1";
NLSF.constr$ = "0<w3<1";
NLSF.constr$ = "w1+w2+w3=1";
NLSF.constraints = 1;
NLSF.Wtype = 0;
NLSF.keepParam = 1;

for(lsi=0; lsi<(length2-length1+1)/interval; lsi++)
{
printf("------%d------\n",lsi);
//Initial Params.
NLSF.p1=weight1[interval*lsi];
NLSF.p2=weight2[interval*lsi];
NLSF.p3=weight3[interval*lsi];
NLSF.v1=1;
NLSF.v2=1;
NLSF.v3=1;
NLSF.dataBegin = lsi*interval;
NLSF.dataEnd = lsi*interval+interval-1;
//fitting
NLSF.Iterate(10);
NLSF.Iterate(10);
//record fitting result
for(lsj=0; lsj<interval; lsj++)
{
weight1[lsj+lsi*interval]=NLSF.p1;
weight2[lsj+lsi*interval]=NLSF.p2;
weight3[lsj+lsi*interval]=NLSF.p3;
}//lsj
}//lsi

NLSF.End(13)
}

=================================================================
Zhou Zeng, Shang Hai Jiao Tong University, China

Mike Buess

USA
3037 Posts

Posted - 05/31/2007 :  12:16:01 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Once again I see no obvious errors and naturally I have no data to test with. A few general comments/tips...

1. The "general operation error" is probably caused by interrupting the fitting function with Esc. I doubt if it has anything to do with slowing down the fitting with successive lsi iterations.

2. It looks like you save the parameters from each lsi iteration in w1, w2 and w3. Do those parameters agree with those obtained for same data ranges with the Advanced Fitter?

3. As I said in a previous post the order of nlsf execution is often critical and sometimes it is not obvious what the correct order should be. Try adding a few diagnostic messages, in particular insert printf("%d: Begin=%d, End=%d\n", lsi, nlsf.dataBegin, nlsf.dataEnd); just before the nlsf.iterate commands. That will tell you if your ranges are correct. You can also establish a breakpoint at the first nlsf.iterate command to check the value of any variable. (See the CodeBuilder User's Guide : Debugger topic of Help > Programming.) For testing I would limit the number of lsi iterations to 5 or 10 so you don't need to Esc.

4. As I said at the end of my last post you are defining the constraints incorrectly. They should all appear in one string...

// NLSF.constr$ = "0<w1<1";
// NLSF.constr$ = "0<w2<1"; // replaces 0<w1<1
// NLSF.constr$ = "0<w3<1"; // replaces 0<w2<1
// NLSF.constr$ = "w1+w2+w3=1"; // replaces 0<w3<1
NLSF.constr$ = "0<w1<1;0<w2<1;0<w3<1;w1+w2+w3=1";

That is irrelevant to your current problem but the way you were doing it results in the single constraint "w1+w2+w3=1".

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 05/31/2007 12:18:00 PM
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