TPCCLIB
Loading...
Searching...
No Matches
tgo.c File Reference

Topographical minimization algorithm. More...

#include "libtpcmodel.h"

Go to the source code of this file.

Macros

#define RAND_MAX   32767
 
#define TGO_SAMPLNR   1000
 

Functions

int tgo (double *lowlim, double *uplim, double(*objf)(int, double *, void *), void *objfData, int dim, int neighNr, double *fmin, double *gmin, int samNr, int tgoNr, int verbose)
 
void tgoRandomParameters (TGO_POINT *p, int parNr, int sNr, double *low, double *up)
 
void tgoRandomParametersST (TGO_POINT *p, int parNr, int sNr, double *low, double *up)
 

Variables

int TGO_SQUARED_TRANSF = 1
 
int TGO_LOCAL_INSIDE = 1
 
int TGO_LOCAL_OPT = 0
 

Detailed Description

Topographical minimization algorithm.

Author
Kaisa Sederholm, Vesa Oikonen

TGO searches the global minimum of a function using clusterization. Calls a local minimization algorithm. Based on an algorithm by Aimo Torn and Sami Viitanen. See the article Topographical Global optimization in: C.A. Floudas and P.M. Pardalos (eds.) Recent advances in Global Optimization, Princeton University Press, 1992, https://doi.org/10.1007/978-1-4613-3437-8_22

Definition in file tgo.c.

Macro Definition Documentation

◆ RAND_MAX

#define RAND_MAX   32767

Max nr for random nr generator

Definition at line 18 of file tgo.c.

◆ TGO_SAMPLNR

#define TGO_SAMPLNR   1000

Sample nr for TGO; must be even number.

Definition at line 23 of file tgo.c.

Referenced by tgo().

Function Documentation

◆ tgo()

int tgo ( double * lowlim,
double * uplim,
double(* objf )(int, double *, void *),
void * objfData,
int dim,
int neighNr,
double * fmin,
double * gmin,
int samNr,
int tgoNr,
int verbose )

Topographical minimization algorithm, that searches the global minimum of a function using clusterization. Calls a local minimization algorithm. Based on an algorithm by Aimo Torn and Sami Viitanen.

Returns
Returns 0, if ok.
See also
tgoRandomParameters, powell, simplex, bobyqa, nlopt1D
Parameters
lowlimLower limits for the parameters.
uplimUpper limits for the parameters.
objfThe object function.
objfDataData to objective function; NULL if not needed.
dimDimension = nr of parameters.
neighNrNr of neighbours to investigate; enter large nr relative to samNr (below) if only few local minima are expected.
fminFunction value at global minimum.
gminGlobal minimum = parameter estimates.
samNrNr of points to sample in one iteration; enter larger samNr if nr of iterations (below) is small.
tgoNrNr of TGO iterations; enter 0 to use the default; enter 1 to run TGO just once ie TGO instead of iTGO. Large iteration nr is needed if samNr (above) would otherwise require too much memory.
verboseVerbose level; if zero, then nothing is printed into stdout or stderr.

Definition at line 39 of file tgo.c.

66 {
67 int i, j, k, l, IDmin, itNr, samplNr, topoNr, badNr, nevals=0, ret;
68 double *delta, temp, min, *tempp, deltaf, tol;
69 TGO_POINT *sampled_points;
70 int fixed_n, fitted_n;
71
72
73 if(verbose>0) {printf("in tgo()\n"); fflush(stdout);}
74 if(TGO_LOCAL_OPT==1) {
75 if(verbose>0) printf("local optimization routine: bobyqa\n");
76 } else {
77 if(verbose>0) printf("local optimization routine: powell\n");
78 }
79
80 /* Check input */
81 if(lowlim==NULL || uplim==NULL || objf==NULL || dim<=0) return(1);
82 if(fmin==NULL || gmin==NULL) return(1);
83
84 /* Check if any of parameters is fixed */
85 for(i=0, fixed_n=0; i<dim; i++) if(uplim[i]<=lowlim[i]) fixed_n++;
86 fitted_n=dim-fixed_n;
87 if(verbose>1) printf("%d parameter(s) are fixed.\n", fixed_n);
88 if(fitted_n<1) return(1);
89
90 /* Continue input checking */
91 if(samNr<=0) samplNr=TGO_SAMPLNR; else samplNr=samNr;
92 if(samplNr&1) samplNr++; // If number is odd, then add 1
93 if(neighNr>samplNr-1) neighNr=samplNr-1; // Make sure "neighNr" isn't too big
94 if(tgoNr<1) tgoNr=fitted_n; // Set TGO iteration number, if not set by user
95 if(verbose>1) {
96 printf("samplNr := %d\n", samplNr);
97 printf("neighNr := %d\n", neighNr);
98 printf("tgoNr := %d\n", tgoNr);
99 if(verbose>2) {
100 printf("iTGO limits: [%g,%g]", lowlim[0], uplim[0]);
101 for(i=1; i<dim; i++) printf(" [%g,%g]", lowlim[i], uplim[i]);
102 printf("\n");
103 }
104#ifdef OMP_NUM_THREADS
105 printf("OMP_NUM_THREADS := %d\n", OMP_NUM_THREADS);
106#endif
107 fflush(stdout);
108 }
109
110 /* Allocate memory */
111 sampled_points=(TGO_POINT*)calloc(samplNr, sizeof(TGO_POINT));
112 if(sampled_points==NULL) return(2);
113 for(i=0; i<samplNr; i++) {
114 sampled_points[i].topomin=0;
115 sampled_points[i].fvalue=0.0;
116 }
117 delta=(double*)malloc(dim*sizeof(double));
118 tempp=(double*)malloc(samplNr*sizeof(double));
119 if(delta==NULL || tempp==NULL) {free(sampled_points); return(2);}
120
121 /* Set seed for random number generator */
122 drandSeed(1);
123
124 /*
125 * Iterative TGO, or non-iterative if tgoNr==1
126 */
127 for(l=0; l<tgoNr; l++) {
128
129 if(verbose>2) {printf("TGO Loop # %d: \n", l+1); fflush(stdout);}
130
131 /*
132 * Sample N points in the feasible region and compute the object function
133 * values for those points which do not already have it.
134 */
135 if(TGO_SQUARED_TRANSF==1)
136 tgoRandomParametersST(sampled_points, dim, samplNr, lowlim, uplim);
137 else
138 tgoRandomParameters(sampled_points, dim, samplNr, lowlim, uplim);
139 badNr=0;
140 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==0) {
141 sampled_points[i].fvalue=objf(dim, sampled_points[i].par, objfData);
142 /* If function return value was not normal then we'll try
143 later (twice) with new guesses */
144 if(!isfinite(sampled_points[i].fvalue)) {
145 badNr++;
146 if(verbose>5) {
147 printf("this point did not give normal return value:\n");
148 for(k=0; k<dim; k++) printf(" %10.2e", sampled_points[i].par[k]);
149 printf("\n");
150 }
151 }
152 }
153 if(verbose>4 && badNr>0) printf("Nr of bad points: %d\n", badNr);
154 /* New guesses for bad points */
155 k=0; while(k<2 && badNr>0) {
156 badNr=0; k++;
157 for(i=0; i<samplNr; i++)
158 if(sampled_points[i].topomin==0 && !isfinite(sampled_points[i].fvalue)) {
159 /* sample a new random point */
160 if(TGO_SQUARED_TRANSF==1)
161 tgoRandomParametersST(sampled_points+i, dim, 1, lowlim, uplim);
162 else
163 tgoRandomParameters(sampled_points+i, dim, 1, lowlim, uplim);
164 /* compute the object function value for that */
165 sampled_points[i].fvalue=objf(dim, sampled_points[i].par, objfData);
166 if(!isfinite(sampled_points[i].fvalue)) badNr++;
167 }
168 if(verbose>4 && badNr>0) printf("Nr of bad points: %d\n", badNr);
169 }
170 /* Print sampled points */
171 if(verbose>6) {
172 printf("Sampled points:\n");
173 for(j=0; j<samplNr; j++) {
174 printf("%d", j+1);
175 for(i=0; i<dim; i++) printf(" %e ", sampled_points[j].par[i]);
176 printf("=>%e\n", sampled_points[j].fvalue);
177 }
178 fflush(stdout);
179 }
180 /* Object functions values must be good for at least NeigNr points */
181 if(l==0 && (samplNr-badNr)<=neighNr) {
182 if(verbose>0) {
183 printf("Error in TGO: invalid function return value from all points.\n");
184 fflush(stdout);
185 }
186 free(sampled_points); free(delta); free(tempp);
187 return(3);
188 }
189
190 /*
191 * For each point i find out if it is a "topografic minimum"
192 * = better than k neighbour points
193 */
194 /* Save the distances to point i in the vector tempp */
195 /* Find the closest neighbour from {x1,..,xn}/{xi} k times, */
196 /* extracting it after comparing */
197 for(i=0, topoNr=0; i<samplNr; i++) {
198 sampled_points[i].topomin=0;
199 /* If function value is not ok, then point cannot be minimum */
200 if(!isfinite(sampled_points[i].fvalue)) continue;
201
202 /* Compute the (scaled) distances */
203 for(j=0; j<samplNr; j++) {
204 tempp[j]=1.0E+99;
205 if(i!=j) {
206 for(k=0, tempp[j]=0.0; k<dim; k++) {
207 deltaf=uplim[k]-lowlim[k]; if(deltaf<=0.0) continue;
208 temp=sampled_points[i].par[k]-sampled_points[j].par[k];
209 if(deltaf>1.0E-20) temp/=deltaf;
210 if(isfinite(temp)) tempp[j] += temp*temp;
211 }
212 /* Distance is computed as square root, but it does not affect
213 the order of distances, and sqrt() is relatively slow */
214 /*tempp=sqrt(tempp);*/
215 }
216 }
217
218 /* Find the closest neighbours */
219 /* At the same time, collect info for max fvalue of the neighbours
220 and for the mean distance to every direction */
221 for(k=0; k<dim; k++) sampled_points[i].delta[k]=0.0; // Init delta array
222 sampled_points[i].fvalrange=sampled_points[i].fvalue;
223 for(j=0; j<neighNr; j++) {
224 min=tempp[0]; IDmin=0;
225 for(k=1; k<samplNr; k++) {if(tempp[k]<min) {min=tempp[k]; IDmin=k;}}
226 tempp[IDmin]=1e+99; // so that this will not be used again
227 /* If point i is worse than any of the closest neighbours, then
228 point i is not a topographic minimum; then stop this loop and go to
229 the next point i+1 */
230 if(isfinite(sampled_points[IDmin].fvalue) &&
231 sampled_points[IDmin].fvalue<sampled_points[i].fvalue) break;
232
233 /* Sum the distances to every direction for delta calculation */
234 for(k=0; k<dim; k++)
235 sampled_points[i].delta[k]+=
236 fabs(sampled_points[i].par[k]-sampled_points[IDmin].par[k]);
237 if(isfinite(sampled_points[IDmin].fvalue) &&
238 sampled_points[IDmin].fvalue>sampled_points[i].fvalrange)
239 sampled_points[i].fvalrange=sampled_points[IDmin].fvalue;
240 } // next neighbour point
241
242 /* If this was NOT a topographic minimum, then continue with the next i */
243 if(j!=neighNr) continue;
244 /* otherwise mark this as topografic minimum (TM) */
245 sampled_points[i].topomin=1; topoNr++;
246
247 /* Compute the mean distance of neighbours from the TM in each
248 dimension; local optimization delta will be based on that */
249 for(k=0; k<dim; k++) sampled_points[i].delta[k]/=(double)neighNr;
250 /* Compute the max range in fvalues */
251 sampled_points[i].fvalrange-=sampled_points[i].fvalue;
252
253 } /* next sample */
254 if(verbose>2) {printf(" %d topographical minima\n", topoNr); fflush(stdout);}
255
256 /* Check that if no topographical minimum was found, then set the smallest */
257 /* minimum as 'topographical' minimum */
258 if(topoNr==0) {
259 min=sampled_points[0].fvalue; IDmin=0;
260 for(k=1; k<samplNr; k++)
261 if(!isfinite(min) || sampled_points[k].fvalue<min) {
262 min=sampled_points[k].fvalue; IDmin=k;}
263 sampled_points[IDmin].topomin=1;
264 for(k=0; k<dim; k++)
265 sampled_points[IDmin].delta[k]=0.1*(uplim[k]-lowlim[k]);
266 sampled_points[i].fvalrange+=100.0*fabs(sampled_points[i].fvalue);
267 if(verbose>2) {
268 printf(" ; therefore minimum was set to point %d at %e\n",
269 IDmin, sampled_points[IDmin].fvalue);
270 fflush(stdout);
271 }
272 topoNr=1;
273 }
274 if(verbose>3) { // Print the best TM
275 for(i=0, min=1e+99, IDmin=0; i<samplNr; i++)
276 if(sampled_points[i].topomin==1) {
277 if(isfinite(sampled_points[i].fvalue) && sampled_points[i].fvalue<min)
278 {
279 min=sampled_points[i].fvalue; IDmin=i;
280 }
281 }
282 printf(" best topographical min:"); fflush(stdout);
283 for(k=0; k<dim; k++) printf(" %e", sampled_points[IDmin].par[k]);
284 printf(" => %e\n", sampled_points[IDmin].fvalue); fflush(stdout);
285 }
286
287 if(TGO_LOCAL_INSIDE==1) {
288 /* Local optimization for each TM */
289 if(verbose>2) printf("local optimization for each TM\n");
290 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
291 //tol=sampled_points[IDmin].fvalue*1.0E-02;
292 //for(k=0; k<dim; k++) delta[k]=sampled_points[i].delta[k];
293 for(k=0; k<dim; k++) delta[k]=0.1*sampled_points[i].delta[k];
294 if(verbose>3) printf("point %d: original fvalue=%.2e\n",
295 i+1, sampled_points[i].fvalue);
296 if(TGO_LOCAL_OPT==1) {
297 tol=1.0E-08; //tol=1.0E-09;
298 ret=bobyqa(dim, 0, sampled_points[i].par, lowlim, uplim, delta, 0.0, 1.0E-03,
299 1.0E-10, tol, tol, 2000, &nevals,
300 &sampled_points[i].fvalue, objf, objfData, NULL, verbose-3);
301 if(ret<0 && verbose>0) {
302 printf("bobyqa error %d\n", ret); fflush(stdout);}
303 if(ret<0 && ret!=BOBYQA_ROUNDOFF_LIMITED) {
304 free(sampled_points); free(delta); free(tempp);
305 return(5);
306 }
307 if(verbose>3) {
308 printf(" local opt => %.2e (nr of evals=%d)\n",
309 sampled_points[i].fvalue, nevals);
310 fflush(stdout);
311 }
312 } else {
313 itNr=40; //itNr=100;
314 tol=1.0E-03; //tol=2.0E-03; //tol=1.0E-09;
315 POWELL_LINMIN_MAXIT=30; // 100;
316 ret=powell(sampled_points[i].par, delta, dim, tol, &itNr,
317 &sampled_points[i].fvalue, objf, objfData, verbose-3);
318 if(ret>1 && verbose>0) {printf("powell error %d\n", ret); fflush(stdout);}
319 if(ret>3) {
320 free(sampled_points); free(delta); free(tempp);
321 return(5);
322 }
323 if(verbose>3) {
324 printf(" local opt => %.2e (itNr=%d)\n",
325 sampled_points[i].fvalue, itNr);
326 fflush(stdout);
327 }
328 }
329 }
330 } // end of local optimizations inside this iTGO loop
331
332 } /* end of tgo iterations */
333
334 if(verbose>1) { // Print the final topographical minima
335 if(verbose>2) printf("Final topographical minima and deltas\n");
336 else printf("Final topographical minima\n");
337 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
338 k=0; printf(" %3d: %.2e", i, sampled_points[i].par[k]);
339 for(k=1; k<dim; k++) printf(" %.2e", sampled_points[i].par[k]);
340 printf(" => %.2e\n", sampled_points[i].fvalue); fflush(stdout);
341 if(verbose>2) {
342 k=0; printf(" %.2e", sampled_points[i].delta[k]);
343 for(k=1; k<dim; k++) printf(" %.2e", sampled_points[i].delta[k]);
344 printf(" => %.2e\n", sampled_points[i].fvalrange); fflush(stdout);
345 }
346 }
347 }
348
349 if(TGO_LOCAL_INSIDE==0) {
350 /*
351 * Use the points in TM as starting points for local optimization;
352 * this first local opt is done only if not done already inside iTGO
353 */
354 if(verbose>2) {printf("Topographic minima:\n"); fflush(stdout);}
355 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
356 //tol=sampled_points[IDmin].fvalue*1.0E-02;
357 for(k=0; k<dim; k++) {
358 if(verbose>2) {printf("%e ", sampled_points[i].par[k]); fflush(stdout);}
359 delta[k]=0.1*sampled_points[i].delta[k];
360 }
361 if(verbose>3) {printf("=> %e ", sampled_points[i].fvalue); fflush(stdout);}
362 if(TGO_LOCAL_OPT==1) {
363 tol=1.0E-09; //tol=1.0E-09;
364 ret=bobyqa(dim, 0, sampled_points[i].par, lowlim, uplim, delta, 0.0, 1.0E-03,
365 1.0E-10, tol, tol, 2000, &nevals,
366 &sampled_points[i].fvalue, objf, objfData, NULL, verbose-3);
367 if(ret<0 && verbose>0) {
368 printf("bobyqa error %d\n", ret); fflush(stdout);}
369 if(ret<0 && ret!=BOBYQA_ROUNDOFF_LIMITED) {
370 free(sampled_points); free(delta); free(tempp);
371 return(5);
372 }
373 if(verbose>2) {
374 printf("local opt 1st round point %d => %e (nr of evals=%d)\n",
375 i+1, sampled_points[i].fvalue, nevals);
376 fflush(stdout);
377 }
378 } else {
379 itNr=50; //itNr=100;
380 tol=1.0E-03; //tol=1.0E-04;
381 POWELL_LINMIN_MAXIT=60; // POWELL_LINMIN_MAXIT=50; // 100;
382 ret=powell(sampled_points[i].par, delta, dim, tol, &itNr,
383 &sampled_points[i].fvalue, objf, objfData, verbose-3);
384 if(ret>1 && verbose>0) {printf("powell error %d\n", ret); fflush(stdout);}
385 if(ret>3) {
386 if(verbose>0) {printf("powell error %d\n", ret); fflush(stdout);}
387 free(sampled_points); free(delta); free(tempp);
388 return(5);
389 }
390 if(verbose>2) {
391 printf("=> %e (itNr=%d) ", sampled_points[i].fvalue, itNr);
392 fflush(stdout);
393 }
394 }
395 }
396 if(verbose>0) { // Print the topographical minima after local optimization
397 printf("Final topographical minima after local optimization\n");
398 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
399 k=0; printf(" %3d: %.2e", i, sampled_points[i].par[k]);
400 for(k=1; k<dim; k++) printf(" %.2e", sampled_points[i].par[k]);
401 printf(" => %.2e\n", sampled_points[i].fvalue); fflush(stdout);
402 }
403 }
404 }
405
406 /* Rerun of local optimization with smaller tolerance and delta */
407 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
408 //tol=sampled_points[IDmin].fvalue*1.0E-04;
409 for(k=0; k<dim; k++) delta[k]=0.1*sampled_points[i].delta[k];
410 if(TGO_LOCAL_OPT==1) {
411 tol=1.0E-10;
412 ret=bobyqa(dim, 0, sampled_points[i].par, lowlim, uplim, delta, 0.0, 1.0E-05,
413 1.0E-10, tol, tol, 1000, &nevals,
414 &sampled_points[i].fvalue, objf, objfData, NULL, verbose-3);
415 if(ret<0 && verbose>0) {
416 printf("bobyqa error %d\n", ret); fflush(stdout);}
417 if(ret<0 && ret!=BOBYQA_ROUNDOFF_LIMITED) {
418 free(sampled_points); free(delta); free(tempp);
419 return(5);
420 }
421 if(verbose>2) {
422 printf("local opt 2nd round point %d => %e (nr of evals=%d)\n",
423 i+1, sampled_points[i].fvalue, nevals);
424 fflush(stdout);
425 }
426 } else {
427 itNr=40; /*itNr=100;*/
428 tol=1.0E-04; //tol=1.0E-03; //tol=1.0E-08;
429 POWELL_LINMIN_MAXIT=60; // 100;
430 ret=powell(sampled_points[i].par, delta, dim, tol, &itNr,
431 &sampled_points[i].fvalue, objf, objfData, verbose-3);
432 if(ret>1 && verbose>0) {printf("powell error %d\n", ret); fflush(stdout);}
433 if(ret>3) {
434 free(sampled_points); free(delta); free(tempp);
435 return(6);
436 }
437 if(verbose>2) {
438 printf("=> %e (itNr=%d)\n", sampled_points[i].fvalue, itNr);
439 fflush(stdout);
440 }
441 }
442 }
443
444 if(verbose>0) { // Print the topographical minima after 2nd local optimization
445 printf("Final topographical minima after 2nd local optimization\n");
446 for(i=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
447 k=0; printf(" %3d: %.2e", i, sampled_points[i].par[k]);
448 for(k=1; k<dim; k++) printf(" %.2e", sampled_points[i].par[k]);
449 printf(" => %.2e\n", sampled_points[i].fvalue); fflush(stdout);
450 }
451 }
452
453
454 /*
455 * Find the best locally optimized TM and run local opt again from
456 * this point with better accuracy
457 */
458
459 for(i=0, min=1e+99, IDmin=0; i<samplNr; i++) if(sampled_points[i].topomin==1) {
460 if(isfinite(sampled_points[i].fvalue) && sampled_points[i].fvalue<min) {
461 min=sampled_points[i].fvalue; IDmin=i;}
462 }
463 if(verbose>1) {
464 printf("Best topographical minimum:");
465 for(k=0; k<dim; k++) printf("%e ", sampled_points[IDmin].par[k]);
466 printf("-> %e \n", sampled_points[IDmin].fvalue); fflush(stdout);
467 }
468
469 /* Rerun of local optimization to the best point */
470 deltaf=0.01; tol=5.0E-04; //tol=1.0E-15;
471 do {
472 for(k=0; k<dim; k++) delta[k]=deltaf*sampled_points[IDmin].delta[k];
473 //for(k=0; k<dim; k++) delta[k]=deltaf*(uplim[k]-lowlim[k]);
474 if(TGO_LOCAL_OPT==1) {
475 ret=bobyqa(dim, 0, sampled_points[IDmin].par, lowlim, uplim, delta, 0.0, tol, // !!!
476 1.0E-10, tol, tol, 5000, &nevals,
477 &sampled_points[IDmin].fvalue, objf, objfData, NULL, verbose-3);
478 if(ret<0 && verbose>0) {
479 printf("bobyqa error %d\n", ret); fflush(stdout);}
480 if(ret<0 && ret!=BOBYQA_ROUNDOFF_LIMITED) {
481 free(sampled_points); free(delta); free(tempp);
482 return(5);
483 }
484 if(verbose>2) {
485 printf("local opt of the best point with tol=%g => %e (nr of evals=%d)\n",
486 tol, sampled_points[IDmin].fvalue, nevals);
487 fflush(stdout);
488 }
489 itNr=nevals;
490 deltaf*=0.5; tol*=0.1;
491 } else {
492 itNr=100;
493 POWELL_LINMIN_MAXIT=100; // 100;
494 ret=powell(sampled_points[IDmin].par, delta, dim, tol, &itNr,
495 &sampled_points[IDmin].fvalue, objf, objfData, verbose-3);
496 if(ret>1 && verbose>0) {printf("powell error %d\n", ret); fflush(stdout);}
497 if(ret>3) {
498 free(sampled_points); free(delta); free(tempp);
499 return(7);
500 }
501 if(verbose>1) {
502 printf(" powell once more with %d iteration(s) -> WSS=%e\n",
503 itNr, sampled_points[IDmin].fvalue);
504 fflush(stdout);
505 }
506 //deltaf*=0.5; tol*=0.5;
507 deltaf*=0.5; tol*=0.25;
508 }
509 } while(itNr>1 && deltaf>1.0E-05);
510//} while(itNr>1 && deltaf>1.0E-15);
511
512
513 /* Save best point to gmin */
514 for(k=0; k<dim; k++) gmin[k]=sampled_points[IDmin].par[k];
515 *fmin=sampled_points[IDmin].fvalue;
516 if(!isfinite(sampled_points[IDmin].fvalue)) {
517 if(verbose>0) {printf("TGO error: valid minimum value was not reached.\n");
518 fflush(stdout);}
519 free(sampled_points); free(delta); free(tempp); return(9);
520 }
521
522 /* Exit TGO */
523 free(sampled_points); free(delta); free(tempp);
524 if(verbose>0) {printf("out of tgo\n"); fflush(stdout);}
525 return(0);
526} /* end tgo */
bobyqa_result bobyqa(int n, int npt, double *x, const double *xl, const double *xu, const double *dx, const double rhoend, double xtol_rel, double minf_max, double ftol_rel, double ftol_abs, int maxeval, int *nevals, double *minf, double(*f)(int n, double *x, void *objf_data), void *objf_data, double *working_space, int verbose)
Definition bobyqa.c:40
unsigned int drandSeed(short int seed)
Make and optionally set the seed for rand(), drand, drandRange, and drandGaussian().
Definition gaussdev.c:63
int powell(double *p, double *delta, int parNr, double ftol, int *iterNr, double *fret, double(*_fun)(int, double *, void *), void *fundata, int verbose)
Definition powell.c:43
int POWELL_LINMIN_MAXIT
Definition powell.c:11
double delta[MAX_PARAMS]
double fvalrange
double par[MAX_PARAMS]
double fvalue
void tgoRandomParameters(TGO_POINT *p, int parNr, int sNr, double *low, double *up)
Definition tgo.c:533
void tgoRandomParametersST(TGO_POINT *p, int parNr, int sNr, double *low, double *up)
Definition tgo.c:564
int TGO_LOCAL_INSIDE
Definition tgo.c:29
#define TGO_SAMPLNR
Definition tgo.c:23
int TGO_LOCAL_OPT
Definition tgo.c:31
int TGO_SQUARED_TRANSF
Definition tgo.c:27

◆ tgoRandomParameters()

void tgoRandomParameters ( TGO_POINT * p,
int parNr,
int sNr,
double * low,
double * up )

Create randomized parameters for TGO.

See also
tgoRandomParametersST
Parameters
pPointer to list of TGO points.
parNrNr of parameters in the point.
sNrNr of TGO points.
lowList of lower limits for each parameter.
upList of upper limits for each parameter.

Definition at line 533 of file tgo.c.

544 {
545 int i, j;
546 double dif;
547
548 for(j=0; j<parNr; j++) {
549 dif=up[j]-low[j];
550 if(dif<=0.0) {
551 for(i=0; i<sNr; i++) if(p[i].topomin==0) p[i].par[j]=low[j];
552 } else {
553 for(i=0; i<sNr; i++) if(p[i].topomin==0) {
554 p[i].par[j]= drand()*dif + low[j];
555 }
556 }
557 }
558}
double drand()
Definition gaussdev.c:142

Referenced by tgo().

◆ tgoRandomParametersST()

void tgoRandomParametersST ( TGO_POINT * p,
int parNr,
int sNr,
double * low,
double * up )

Create randomized parameters for TGO with square-root transformation, that is, parameter distribution is biased towards low absolute value.

See also
tgoRandomParameters
Parameters
pPointer to list of TGO points.
parNrNr of parameters in the point.
sNrNr of TGO points.
lowList of lower limits for each parameter.
upList of upper limits for each parameter.

Definition at line 564 of file tgo.c.

575 {
576 int i, j;
577 double v, stl, stu, dif;
578
579 for(j=0; j<parNr; j++) {
580 dif=up[j]-low[j];
581 if(dif<=0.0) {
582 for(i=0; i<sNr; i++) if(p[i].topomin==0) p[i].par[j]=low[j];
583 } else {
584 stl=copysign(sqrt(fabs(low[j])),low[j]); if(!isnormal(stl)) stl=0.0;
585 stu=copysign(sqrt(fabs(up[j])), up[j]); if(!isnormal(stu)) stu=0.0;
586 dif=stu-stl;
587 for(i=0; i<sNr; i++) if(p[i].topomin==0) {
588 v=drand()*dif + stl;
589 p[i].par[j]=copysign(v*v, v);
590 }
591 }
592 }
593}

Referenced by tgo().

Variable Documentation

◆ TGO_LOCAL_INSIDE

int TGO_LOCAL_INSIDE = 1

Local optimization outside (0) or inside (1) iTGO

Definition at line 29 of file tgo.c.

Referenced by tgo().

◆ TGO_LOCAL_OPT

int TGO_LOCAL_OPT = 0

Local optimization is done using Powell-Brent (0) or Bobyqa (1).

Definition at line 31 of file tgo.c.

Referenced by tgo().

◆ TGO_SQUARED_TRANSF

int TGO_SQUARED_TRANSF = 1

Biased (1) or even (0) parameter distribution

Definition at line 27 of file tgo.c.

Referenced by tgo().