| Author |
Topic  |
|
|
bluecourse
China
Posts |
Posted - 05/29/2007 : 08:07:57 AM
|
Origin Version (Select Help-->About Origin 7.5): Operating System:XP NLSF:the use about NLSF.dataBegin and NLSF.dataEnd Hi, Mike I have a large data set, it's row range is [1,414024] and column range is [1,20]. I would like to fitting this data set by stages by using NLSF.dataBegin and NLSF.dataEnd. For example: Fitting1: dataBegin=1, dataEnd=1000; Fitting2: dataBegin=1001, dataEnd=2000; Fitting3: dataBegin=2001, dataEnd=3000; ...... ...... ...... ...... The problm is origin produce an error [******Error: general operation failure******] when fitting data. But when I extract a sub data set (such as row range is [1,5000]) from the large data set by [Analysis----->Extract Worksheet Data...] and fitting it by the same way, it's works very well. I would like to know whether origin has the max length limitation when using NLSF.dataBegin and NLSF.dataEnd or there are some unconspicuous errors in my code, such as forget free memory when recall fitting function many times. The following is my Origin C code. The data range is setted from [1000,251000] by NLSF.dataBegin and NLSF.dataEnd, its inside the range of worksheet [1,414024]. Can you help me? Good luck, Many thanks. ---------------------------------------------------------------------
void BRDFFitting(int dataBegin, int dataEnd, string funcName, double initialParam[], int iterateNumber) { //Define data type. int lsi,lsj; double lsd,lsd2,lsd3,lsd4; string str; Dataset lsds; Worksheet wks = Project.ActiveLayer();
//Define Process. using NLSF = LabTalk.NLSF; NLSF.begin(); NLSF.cleanUpFitData(); NLSF.msgPrompt=0; NLSF.Output(0); NLSF.Func$ = funcName;
//Set initial params. if(funcName=="WardISO") { NLSF.p1=initialParam[0]; NLSF.p2=initialParam[1]; NLSF.p3=initialParam[2]; NLSF.p4=initialParam[3]; NLSF.p5=initialParam[4]; NLSF.p6=initialParam[5]; NLSF.p7=initialParam[6]; NLSF.v1=1; NLSF.v2=1; NLSF.v3=1; NLSF.v4=1; NLSF.v5=1; NLSF.v6=1; NLSF.v7=1; NLSF.s7=1; }//for lsi
//Allocate Data. NLSF.xMode =2; lsds.Attach(wks, 3); NLSF.x1$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 4); NLSF.x2$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 5); NLSF.x3$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 6); NLSF.x4$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 7); NLSF.x5$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 8); NLSF.x6$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 9); NLSF.x7$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 10); NLSF.x8$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 11); NLSF.x9$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 17); NLSF.x10$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 18); NLSF.x11$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 19); NLSF.x12$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 0); NLSF.y1$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 1); NLSF.y2$=lsds.GetName(); lsds.Detach(); lsds.Attach(wks, 2); NLSF.y3$=lsds.GetName(); lsds.Detach(); NLSF.dataBegin=dataBegin; NLSF.dataEnd=dataEnd;
//Define constriant. NLSF.constr$="0<=Rd"; NLSF.constr$="0<=Gd"; NLSF.constr$="0<=Bd"; NLSF.constr$="0<=Rs"; NLSF.constr$="0<=Gs"; NLSF.constr$="0<=Bs"; NLSF.constr$="0<=m<=1"; NLSF.constraints=1;
NLSF.Wtype = 0; NLSF.keepParam=1; //Fitting. NLSF.Iterate(iterateNumber); NLSF.End(13); //Output result. printf("-----Fitting Result---%d--\n", NLSF.curRow); lsd=NLSF.cod; printf("R^2=%f\n",(float)lsd); lsd2=NLSF.p1; lsd3=NLSF.p2; lsd4=NLSF.p3; printf("Diffuse[R,G,B]=%f, %f, %f\n",(float)lsd2, (float)lsd3, (float)lsd4); lsd2=NLSF.p4; lsd3=NLSF.p5; lsd4=NLSF.p6; printf("Specular[R,G,B]=%f, %f, %f\n",(float)lsd2, (float)lsd3, (float)lsd4); lsd2=NLSF.p7; printf("Roughness:%f\n\n",(float)lsd2); //Return fitting parameters. if(funcName=="WardISO") { initialParam[0]=NLSF.p1; initialParam[1]=NLSF.p2; initialParam[2]=NLSF.p3; initialParam[3]=NLSF.p4; initialParam[4]=NLSF.p5; initialParam[5]=NLSF.p6; initialParam[6]=NLSF.p7; }//for lsi
}
//////////////////////////////////////////////////////////////////// void Implementation() { //Define data type. double initialParam[10]; string funcName; int iterateNumber; int dataBegin; int dataEnd; int lsi,lsj; //Define process. initialParam[0]=0.5; initialParam[1]=0.5; initialParam[2]=0.5; initialParam[3]=0.1; initialParam[4]=0.1; initialParam[5]=0.1; initialParam[6]=0.1; funcName="WardISO"; iterateNumber=10; dataBegin=1000; for(lsi=0; lsi<5; lsi++) { dataEnd=dataBegin+1000; BRDFFitting(dataBegin, dataEnd, funcName, initialParam, iterateNumber); dataBegin+=50000; } } --------------------------------------------------------------------- |
|
|
Mike Buess
USA
3037 Posts |
Posted - 05/29/2007 : 10:11:46 AM
|
I can't spot any obvious errors but I think your OC function is much more complicated than is necessary. Try this...
void BRDFFitting(int iterateNumber = 10) { using NLSF = LabTalk.NLSF; NLSF.begin(); NLSF.cleanUpFitData(); NLSF.msgPrompt = 0; NLSF.Output(0); if(NLSF.func$=="WardISO") { NLSF.p1 = 0.5; NLSF.p2 = 0.5; NLSF.p3 = 0.5; NLSF.p4 = 0.1; NLSF.p5 = 0.1; NLSF.p6 = 0.1; NLSF.p7 = 0.1; NLSF.v1 = 1; NLSF.v2 = 1; NLSF.v3 = 1; NLSF.v4 = 1; NLSF.v5 = 1; NLSF.v6 = 1; NLSF.v7 = 1; NLSF.s7 = 1; } else return; // ?? //NLSF.xMode=2; // why this? you don't use nlsf.makecurve() Worksheet wks = Project.ActiveLayer(); NLSF.x1$ = wks.Columns(3).GetDatasetName(); NLSF.x2$ = wks.Columns(4).GetDatasetName(); NLSF.x3$ = wks.Columns(5).GetDatasetName(); NLSF.x4$ = wks.Columns(6).GetDatasetName(); NLSF.x5$ = wks.Columns(7).GetDatasetName(); NLSF.x6$ = wks.Columns(8).GetDatasetName(); NLSF.x7$ = wks.Columns(9).GetDatasetName(); NLSF.x8$ = wks.Columns(10).GetDatasetName(); NLSF.x9$ = wks.Columns(11).GetDatasetName(); NLSF.x10$ = wks.Columns(17).GetDatasetName(); NLSF.x11$ = wks.Columns(18).GetDatasetName(); NLSF.x12$ = wks.Columns(19).GetDatasetName(); NLSF.y1$ = wks.Columns(0).GetDatasetName(); NLSF.y2$ = wks.Columns(1).GetDatasetName(); NLSF.y3$ = wks.Columns(2).GetDatasetName(); //Define constriant. NLSF.constr$ = "0<=Rd;0<=Gd;0<=Bd;0<=Rs;0<=Gs;0<=Bs;0<=m<=1"; NLSF.constraints = 1; NLSF.Wtype = 0; NLSF.keepParam = 1; int dataBegin = 1000; int dataEnd; for(int lsi=0; lsi<5; lsi++) { dataEnd = dataBegin + 1000; NLSF.dataEnd = dataEnd; NLSF.dataBegin = dataBegin; NLSF.Iterate(iterateNumber); NLSF.Iterate(iterateNumber); // repeat once or twice NLSF.Iterate(iterateNumber); //Output result. // NLSF.curRow?? printf("-----Fitting Result--%d to %d--\n", dataBegin, dataEnd); printf("R^2=%f\n",NLSF.cod); // (float) not necessary printf("Diffuse[R,G,B]=%f, %f, %f\n",NLSF.p1, NLSF.p2, NLSF.p3); printf("Specular[R,G,B]=%f, %f, %f\n",NLSF.p4, NLSF.p5, NLSF.p6); printf("Roughness:%f\n\n",NLSF.p7); dataBegin += 50000; } NLSF.End(13); }
...Note, I finally looked at your constraints and realized that the syntax was wrong. All constraints must be specified as a single string as shown above.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 05/29/2007 10:48:42 AM |
 |
|
|
bluecourse
China
Posts |
Posted - 05/30/2007 : 09:14:53 AM
|
| Thanks a lot, Mike, your code is very useful. |
 |
|
| |
Topic  |
|
|
|