TPCCLIB
|
BOBYQA is a derivative-free optimization code with constraints by M. J. D. Powell. Original Fortran code by Powell (2009). More...
#include "libtpcmodel.h"
Go to the source code of this file.
Functions | |
void | bobyqa_update (bobyqa_data *bdata) |
bobyqa_result | bobyqa_rescue (bobyqa_data *bdata) |
void | bobyqa_altmov (bobyqa_data *bdata) |
void | bobyqa_trsbox (bobyqa_data *bdata) |
bobyqa_result | bobyqa_prelim (bobyqa_data *bdata) |
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) |
int | bobyqa_minimize_single_parameter (bobyqa_data *bdata) |
char * | bobyqa_rc (bobyqa_result rc) |
int | fixed_params (int n, const double *lower, const double *upper, const double *delta) |
int | bobyqa_working_memory_size (int n, int fitted_n, int npt, bobyqa_data *bdata) |
bobyqa_result | bobyqa_set_memory (int n, int fitted_n, int npt, bobyqa_data *bdata, double *wm) |
bobyqa_result | bobyqa_free_memory (bobyqa_data *bdata) |
bobyqa_result | bobyqa_reset_memory (bobyqa_data *bdata) |
void | bobyqa_print (bobyqa_data *bdata, int sw, FILE *fp) |
double | bobyqa_x_funcval (bobyqa_data *bdata, double *x) |
void | bobyqa_xfull (bobyqa_data *bdata) |
bobyqa_result | bobyqa_set_optimization (int full_n, double *x, const double *dx, const double *xl, const double *xu, const double rhoend, double xtol_rel, double minf_max, double ftol_rel, double ftol_abs, int maxeval, double(*f)(int n, double *x, void *objf_data), void *objf_data, int verbose, bobyqa_data *bdata) |
void | bobyqb_xupdate (bobyqa_data *bdata) |
void | bobyqb_update_gopt (bobyqa_data *bdata) |
void | bobyqb_shift_xbase (bobyqa_data *bdata) |
void | bobyqb_vlag_beta_for_d (bobyqa_data *bdata) |
int | bobyqb_calc_with_xnew (bobyqa_data *bdata) |
void | bobyqb_next_rho_delta (bobyqa_data *bdata) |
int | bobyqb_do_rescue (bobyqa_data *bdata) |
int | bobyqb_part (bobyqa_data *bdata) |
int | bobyqb_ip_dist (bobyqa_data *bdata) |
void | bobyqb_ip_alternative (bobyqa_data *bdata) |
bobyqa_result | bobyqb (bobyqa_data *bdata) |
void | trsbox_s_multiply (bobyqa_data *bdata) |
void | trsbox_set_xnew (bobyqa_data *bdata) |
BOBYQA is a derivative-free optimization code with constraints by M. J. D. Powell. Original Fortran code by Powell (2009).
Bobyqa seeks the least value of a function of many variables, by applying a trust region method that forms quadratic models by interpolation. There is usually some freedom in the interpolation conditions, which is taken up by minimizing the Frobenius norm of the change to the second derivative of the model, beginning with the zero matrix. The values of the variables are constrained by upper and lower bounds.
This implements the method with a few modifications to make it easier to use at Turku PET Centre. If you are interested to use BOBYQA outside Turku PET Centre, we would strongly suggest using other libraries instead; for example https://dlib.net/ and https://nlopt.readthedocs.io/en/
Definition in file bobyqa.c.
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 ) |
BOBYQA is a derivative-free optimization code with constraints. This function interface is close to the one published by Powell.
n | N must be set to the number of variables (and length of arrays below) |
npt | NPT is the number of interpolation conditions. Its value must be in the interval [N+2,(N+1)(N+2)/2]. Choices that exceed 2*N+1 are not recommended. If set to zero, then bobyqa uses 2*N+1 as default. However, if very high precision is required, relatively high npt seems to be needed. |
x | Initial values of the variables must be set in X(1),X(2),...,X(N). They will be changed to the values that give the least calculated F. |
xl | Lower bounds for X[]: For I=1,2,...,N, XL(I) and XU(I) must provide the lower and upper bounds, respectively, on X(I). The construction of quadratic models requires XL(I) to be strictly less than XU(I) for each I. Further, the contribution to a model from changes to the I-th variable is damaged severely by rounding errors if XU(I)-XL(I) is too small. If xl[i]==xu[i]==x[i], then parameter x[i] is fixed to x[i] and left out of actual bobyqa procedure; parameter(s) can also be fixed by setting dx[i]=0. |
xu | Upper bounds for X[]: For I=1,2,...,N, XL(I) and XU(I) must provide the lower and upper bounds, respectively, on X(I). The construction of quadratic models requires XL(I) to be strictly less than XU(I) for each I. Further, the contribution to a model from changes to the I-th variable is damaged severely by rounding errors if XU(I)-XL(I) is too small. If xl[i]==xu[i]==x[i], then parameter x[i] is fixed to x[i] and left out of actual bobyqa procedure; parameter(s) can also be fixed by setting dx[i]=0. |
dx | Initial step sizes. dx should be set to 1/10 of probable distance from initial guess where the final solution could be; set dx to zero for those parameters that are to be fixed to their initial value. Too high values may lead to error. |
rhoend | Rhoend must be set to the final value of a trust region radius, as a (positive) fraction of dx values given above, for example 1.0E-06. Smaller value adds precision and increases calculation time. Enter <=0 to use default value, calculated using xtol_rel. |
xtol_rel | Relative X tolerance |
minf_max | Stopping rule: maximal allowed function value; when reached, stops. |
ftol_rel | Stopping rule: relative tolerance to function value |
ftol_abs | Stopping rule: absolute tolerance to function value |
maxeval | Stopping rule: max nr of function evaluations |
nevals | Number of function evaluations; this function will initialize this to zero, and in the end returns the number. Enter NULL if not needed. |
minf | Pointer where minimized function value will be written |
f | Objective function has to be provided by the user. It must set F to the value of the objective function for the current values of the variables X(1),X(2),...,X(N), which are generated automatically in a way that satisfies the bounds given in XL and XU. |
objf_data | Pointer to data that is carried over to the function. It is not needed or used by bobyqa. Enter NULL if not needed. |
working_space | The array W will be used for working space. Its length can be calculated using function bobyqa_working_memory_size(). Enter NULL to leave allocating to this function. |
verbose | Verbose level; if zero, then nothing is printed to stderr or stdout |
Definition at line 40 of file bobyqa.c.
Referenced by tgo().
void bobyqa_altmov | ( | bobyqa_data * | bdata | ) |
Bobyqa subroutine altmov
Definition at line 1875 of file bobyqa.c.
Referenced by bobyqb(), bobyqb_ip_alternative(), and bobyqb_part().
bobyqa_result bobyqa_free_memory | ( | bobyqa_data * | bdata | ) |
Free the working memory and memory for data arrays and matrices in BOBYQA structure that was allocated by bobyqa_allocate_memory().
bdata | Pointer to bobyqa struct |
Definition at line 592 of file bobyqa.c.
Referenced by bobyqa(), and bobyqa_set_memory().
int bobyqa_minimize_single_parameter | ( | bobyqa_data * | bdata | ) |
Local one-dimensional minimization, meant to be called from bobyqa() which does not otherwise work with 1-D problems.
Definition at line 210 of file bobyqa.c.
Referenced by bobyqa().
bobyqa_result bobyqa_prelim | ( | bobyqa_data * | bdata | ) |
SUBROUTINE PRELIM sets the elements of XBASE, XPT, FVAL, GOPT, HQ, PQ, BMAT and ZMAT for the first iteration, and it maintains the values of NF and KOPT. The vector X is also changed by PRELIM.
Definition at line 2135 of file bobyqa.c.
Referenced by bobyqb().
void bobyqa_print | ( | bobyqa_data * | bdata, |
int | sw, | ||
FILE * | fp ) |
For testing: print BOBYQA data struct variables to specified file pointer.
bdata | Pointer to bobyqa structure. |
sw | Switch that tells what to print: 0=All; 1=parameters; 2=array sizes; 3=full parameter list; 4=fitted parameters, limits and deltas. |
fp | File pointer where contents are printed; usually stdout. |
Definition at line 640 of file bobyqa.c.
Referenced by bobyqa().
char * bobyqa_rc | ( | bobyqa_result | rc | ) |
Description of bobyqa return code as text string.
Definition at line 381 of file bobyqa.c.
Referenced by bobyqa().
bobyqa_result bobyqa_rescue | ( | bobyqa_data * | bdata | ) |
Bobyqa subroutine rescue: The final elements of BMAT and ZMAT are set in a well-conditioned way to the values that are appropriate for the new interpolation points. The elements of GOPT, HQ and PQ are also revised to the values that are appropriate to the final quadratic model. This function is hardly never called, but it may save the day.
Definition at line 2293 of file bobyqa.c.
Referenced by bobyqb_do_rescue().
bobyqa_result bobyqa_reset_memory | ( | bobyqa_data * | bdata | ) |
Initiate BOBYQA data struct variables before calling bobyqb(). Can be used to reset data variables before calling bobyqb() again with the same problem size, without need to call bobyqa_free_memory() and bobyqa_set_memory() first.
bdata | Pointer to bobyqa struct |
Definition at line 614 of file bobyqa.c.
Referenced by bobyqa_set_memory().
bobyqa_result bobyqa_set_memory | ( | int | n, |
int | fitted_n, | ||
int | npt, | ||
bobyqa_data * | bdata, | ||
double * | wm ) |
Setup working memory and memory for data arrays and matrices in BOBYQA structure. Double memory is either allocated inside this function or preallocated memory can be given as argument.
n | Number of all model parameters. |
fitted_n | Number of fitted (not fixed) model parameters. |
npt | NPT. |
bdata | Pointer to bobyqa structure. |
wm | Enter pointer to preallocated working memory; NULL to allocate it here. |
Definition at line 501 of file bobyqa.c.
Referenced by bobyqa().
bobyqa_result bobyqa_set_optimization | ( | int | full_n, |
double * | x, | ||
const double * | dx, | ||
const double * | xl, | ||
const double * | xu, | ||
const double | rhoend, | ||
double | xtol_rel, | ||
double | minf_max, | ||
double | ftol_rel, | ||
double | ftol_abs, | ||
int | maxeval, | ||
double(* | f )(int n, double *x, void *objf_data), | ||
void * | objf_data, | ||
int | verbose, | ||
bobyqa_data * | bdata ) |
Set optimization parameters and limits in BOBYQA data struct.
full_n | Length of full parameter list. |
x | Pointer to array of full parameters. |
dx | Pointer to array of initial step sizes (deltas). |
xl | Pointer to array of lower limits. |
xu | Pointer to array of upper limits. |
rhoend | Rhoend; enter <=0 to use default value, calculated using xtol_rel. |
xtol_rel | Relative X tolerance. |
minf_max | Stopping rule: maximal allowed function value; when reached, stops. |
ftol_rel | Stopping rule: relative tolerance to function value. |
ftol_abs | Stopping rule: absolute tolerance to function value. |
maxeval | Stopping rule: max nr of function evaluations. |
f | Pointer to object function |
objf_data | Pointer to data that is carried over to the object function. Enter NULL if not needed. |
verbose | Verbose level for all BOBYQA functions; if zero, then nothing is printed to stderr or stdout |
bdata | Pointer to bobyqa structure. |
Definition at line 781 of file bobyqa.c.
Referenced by bobyqa().
void bobyqa_trsbox | ( | bobyqa_data * | bdata | ) |
A version of the truncated conjugate gradient is applied. If a line search is restricted by a constraint, then the procedure is restarted, the values of the variables that are at their bounds being fixed. If the trust region boundary is reached, then further changes may be made to D, each one being in the two dimensional space that is spanned by the current D and the gradient of Q at XOPT+D, staying on the trust region boundary. Termination occurs when the reduction in Q seems to be close to the greatest reduction that can be achieved.
Definition at line 2724 of file bobyqa.c.
Referenced by bobyqb().
void bobyqa_update | ( | bobyqa_data * | bdata | ) |
Bobyqa subroutine update: The arrays BMAT and ZMAT are updated, as required by the new position of the interpolation point that has the index KNEW. The vector VLAG has N+NPT components, set on entry to the first NPT and last N components of the product Hw in equation (4.11) of the Powell (2006) paper on NEWUOA. Further, BETA is set on entry to the value of the parameter with that name, and DENOM is set to the denominator of the updating formula. Elements of ZMAT may be treated as zero if their moduli are at most ZTEST.
Definition at line 2998 of file bobyqa.c.
Referenced by bobyqa_rescue(), and bobyqb_calc_with_xnew().
int bobyqa_working_memory_size | ( | int | n, |
int | fitted_n, | ||
int | npt, | ||
bobyqa_data * | bdata ) |
Calculate the required size of memory to allocate for bobyqa().
n | Number of all model parameters |
fitted_n | Number of fitted (not fixed) model parameters |
npt | NPT |
bdata | Enter pointer to bobyqa struct to set array sizes, otherwise enter NULL |
Definition at line 441 of file bobyqa.c.
Referenced by bobyqa(), and bobyqa_set_memory().
double bobyqa_x_funcval | ( | bobyqa_data * | bdata, |
double * | x ) |
Calculate the objective function value with current scaled parameters values stored in specified array. This function back-scales the parameters to the full parameter list and calls the objective function with full set of parameters, that is, including also fixed parameters which are saved in bobyqa data struct. Also nevals is incremented.
Definition at line 751 of file bobyqa.c.
Referenced by bobyqa_minimize_single_parameter(), bobyqa_prelim(), bobyqa_rescue(), and bobyqb_calc_with_xnew().
void bobyqa_xfull | ( | bobyqa_data * | bdata | ) |
Add the fitted parameters (x[]) to the full parameter list (xfull[]). xfull[] will contain back-scaled parameter values. x[] is not modified.
Definition at line 769 of file bobyqa.c.
Referenced by bobyqa(), and bobyqb_xupdate().
bobyqa_result bobyqb | ( | bobyqa_data * | bdata | ) |
bobyqb (called from bobyqa).
bdata | Data struct for BOBYQA subroutines |
Definition at line 1622 of file bobyqa.c.
Referenced by bobyqa().
int bobyqb_calc_with_xnew | ( | bobyqa_data * | bdata | ) |
Calculate obj function with new variables, and make a new step.
Definition at line 1093 of file bobyqa.c.
Referenced by bobyqb().
int bobyqb_do_rescue | ( | bobyqa_data * | bdata | ) |
Local function for bobyqb
Definition at line 1402 of file bobyqa.c.
Referenced by bobyqb_part().
void bobyqb_ip_alternative | ( | bobyqa_data * | bdata | ) |
Find alternative new positions for the KNEWth interpolation point within distance ADELT of XOPT.
Definition at line 1593 of file bobyqa.c.
Referenced by bobyqb().
int bobyqb_ip_dist | ( | bobyqa_data * | bdata | ) |
void bobyqb_next_rho_delta | ( | bobyqa_data * | bdata | ) |
int bobyqb_part | ( | bobyqa_data * | bdata | ) |
Local bobyqb function
Definition at line 1449 of file bobyqa.c.
Referenced by bobyqb().
void bobyqb_shift_xbase | ( | bobyqa_data * | bdata | ) |
Local bobyqb function xbase_shift(): Severe cancellation is likely to occur if XOPT is too far from XBASE. In this function XBASE is shifted so that XOPT becomes zero. The appropriate changes are made to BMAT and to the second derivatives of the current model, beginning with the changes to BMAT that do not depend on ZMAT. VLAG is used temporarily for working space.
Definition at line 973 of file bobyqa.c.
Referenced by bobyqb(), and bobyqb_ip_alternative().
void bobyqb_update_gopt | ( | bobyqa_data * | bdata | ) |
Local function for updating GOPT
Definition at line 945 of file bobyqa.c.
Referenced by bobyqb(), and bobyqb_do_rescue().
void bobyqb_vlag_beta_for_d | ( | bobyqa_data * | bdata | ) |
Local function for calculating VLAG and BETA for the current choice of D. The scalar product of D with XPT(K,.) is going to be held in W2NPT(NPT+K) for use when VQUAD is calculated.
Definition at line 1055 of file bobyqa.c.
Referenced by bobyqb_part().
void bobyqb_xupdate | ( | bobyqa_data * | bdata | ) |
Local bobyqb function
Definition at line 921 of file bobyqa.c.
Referenced by bobyqb(), bobyqb_calc_with_xnew(), bobyqb_do_rescue(), and bobyqb_part().
int fixed_params | ( | int | n, |
const double * | lower, | ||
const double * | upper, | ||
const double * | delta ) |
Determine how many of model parameters are fixed.
n | Total nr of parameters |
lower | List of lower parameter limits |
upper | List of upper parameter limits |
delta | List of parameter deltas; enter NULL if not available |
Definition at line 418 of file bobyqa.c.
Referenced by bobyqa().
void trsbox_s_multiply | ( | bobyqa_data * | bdata | ) |
This local function multiplies the current S-vector by the second derivative matrix of the quadratic model, putting the product in HS.
Definition at line 2672 of file bobyqa.c.
Referenced by bobyqa_trsbox().
void trsbox_set_xnew | ( | bobyqa_data * | bdata | ) |
Local function for setting XNEW to XOPT+D, giving careful attention to the bounds.
Definition at line 2695 of file bobyqa.c.
Referenced by bobyqa_trsbox().