Skip to content
Snippets Groups Projects
Commit 1aa72b0b authored by vesoik@utu.fi's avatar vesoik@utu.fi
Browse files

fixed stopping rule when dim=1

parent acdb3fef
No related branches found
No related tags found
No related merge requests found
......@@ -126,7 +126,7 @@ int nloptPowellBrent(
}
h/=(double)(nlo->totalNr-fixedNr);
t/=(double)(nlo->totalNr-fixedNr);
if(verbose>2) printf("xdelta_min := %g\nxdelta_max := %g\n", min, max);
if(verbose>2) {printf("xdelta_min := %g\nxdelta_max := %g\n", min, max); fflush(stdout);}
scbd+=log10(max/min); // >1 if param scales are different
t2=small+fabs(t); t=t2;
if(h<100.0*t) h=100.0*t;
......@@ -135,6 +135,7 @@ int nloptPowellBrent(
printf("step := %g\n", h);
printf("scbd := %g\n", scbd);
printf("t(2) := %g\n", t);
fflush(stdout);
}
if(isnan(scbd)) { // checking that user provided xdeltas
statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_INVALID_VALUE);
......@@ -148,6 +149,7 @@ int nloptPowellBrent(
int illc=0;
/* Initialize */
if(verbose>2) {printf("initializing\n"); fflush(stdout);}
unsigned int i, j, dim=nlo->totalNr;
double ldfac; if(illc) ldfac=0.1; else ldfac=0.01;
unsigned int nl=0, kt=0;
......@@ -156,9 +158,19 @@ int nloptPowellBrent(
double ldt=h;
double d[dim], y[dim], z[dim];
// double v[dim][dim];
double **v=malloc(dim*sizeof(double *));
for(i=0; i<dim; i++) v[i]=malloc(dim*sizeof(double));
double **v=malloc(dim*sizeof(double *)); if(v==NULL) {
statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OUT_OF_MEMORY);
return TPCERROR_OUT_OF_MEMORY;
}
for(i=0; i<dim; i++) {
v[i]=malloc(dim*sizeof(double));
if(v[i]==NULL) {
statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_OUT_OF_MEMORY);
return TPCERROR_OUT_OF_MEMORY;
}
}
/* Make a copy of parameter list */
if(verbose>2) {printf("copying parameters\n"); fflush(stdout);}
double p[dim];
for(i=0; i<dim; i++) p[i]=nlo->xfull[i];
......@@ -171,14 +183,17 @@ int nloptPowellBrent(
/* Calculate function value with the initial guess */
if(verbose>2) {printf("evaluating initial guess\n"); fflush(stdout);}
double fx, qf1;
fx=qf1=(*nlo->_fun)(nlo->totalNr, nlo->xfull, nlo->fundata);
nf++;
if(!isfinite(fx)) {
for(i=0; i<dim; i++) free(v[i]);
free(v);
statusSet(status, __func__, __FILE__, __LINE__, TPCERROR_INVALID_VALUE);
return TPCERROR_INVALID_VALUE;
}
if(verbose>1) printf("initial_objfunc := %g\n", fx);
if(verbose>1) {printf("initial_objfunc := %g\n", fx); fflush(stdout);}
/* The main loop */
......@@ -186,7 +201,10 @@ int nloptPowellBrent(
int done=0, nLoop=0, ret=0;
while(!done) {
nLoop++;
if(verbose>2) printf("\n-------------------------------\nloop %d\n", nLoop);
if(verbose>2) {
printf("\n-------------------------------\nloop %d, with %d fcalls\n", nLoop, nf);
fflush(stdout);
}
sf=d[0]; s=d[0]=0.0;
/* Minimize along the first direction */
......@@ -309,7 +327,10 @@ int nloptPowellBrent(
* We are probably in a curved valley, try quadratic extrapolation
*/
/* but only if we have more than one parameter to fit */
if(dim<2) continue;
if(dim<2) {
if(nf>1000) done=1;
continue;
}
/* Praxis quad:
looks for the minimum along a curve defined by q0, q1, and x (q2). */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment