/**
* A parameter for the function line_search_morethuente only.
* This parameter determines which curvature condition to use.
* The default value is 1, implying a strong Wolfe condition.
* If the value is 0, then a weak Wolfe condition is used.
*/
int abs_curv_cond;
/**
* A parameter for the function line_search_morethuente only.
* This parameter determines the interval shrink strategy in line search.
* The default value is 0, guaranteeing at least 2^(-m/2) decreasing of
* uncertainty as trial number m grows. It is used by More and Thuente.
* If the value is 1, then at least 2^(-m) decreasing of uncertainty is
* guaranteed. It is used by Hager and Zhang in TOMS851. The former suits
* well-conditioned functions while the latter suits stiff functions.
*/
int shrink_type;
};
/**
* Default L-BFGS parameters.
*/
static const lbfgs_parameter_t _default_param = {
8,
1.0e-5,
0,
1.0e-5,
0,
60,
1.0e-20,
1.0e+20,
1.0e-4,
0.9,
1.0e-16,
1,
1,
0,
};
/**
* Return values of lbfgs_optimize().
* Roughly speaking, a negative value indicates an error.
*/
enum {
/** L-BFGS reaches convergence. */
LBFGS_CONVERGENCE = 0,
/** L-BFGS satisfies stopping criteria. */
LBFGS_STOP,
/** The initial variables already minimize the objective function. */
LBFGS_ALREADY_MINIMIZED,
/** Unknown error. */
LBFGSERR_UNKNOWNERROR = -1024,
/** Logic error. */
LBFGSERR_LOGICERROR,
/** The minimization process has been canceled. */
LBFGSERR_CANCELED,
/** Invalid number of variables specified. */
LBFGSERR_INVALID_N,
/** Invalid parameter lbfgs_parameter_t::mem_size specified. */
LBFGSERR_INVALID_MEMSIZE,
/** Invalid parameter lbfgs_parameter_t::g_epsilon specified. */
LBFGSERR_INVALID_GEPSILON,
/** Invalid parameter lbfgs_parameter_t::past specified. */
LBFGSERR_INVALID_TESTPERIOD,
/** Invalid parameter lbfgs_parameter_t::delta specified. */
LBFGSERR_INVALID_DELTA,
/** Invalid parameter lbfgs_parameter_t::min_step specified. */
LBFGSERR_INVALID_MINSTEP,
/** Invalid parameter lbfgs_parameter_t::max_step specified. */
LBFGSERR_INVALID_MAXSTEP,
/** Invalid parameter lbfgs_parameter_t::f_dec_coeff specified. */
LBFGSERR_INVALID_FDECCOEFF,
/** Invalid parameter lbfgs_parameter_t::s_curv_coeff specified. */
LBFGSERR_INVALID_SCURVCOEFF,
/** Invalid parameter lbfgs_parameter_t::xtol specified. */
LBFGSERR_INVALID_XTOL,
/** Invalid parameter lbfgs_parameter_t::max_linesearch specified. */
LBFGSERR_INVALID_MAXLINESEARCH,
/** The line-search step went out of the interval of uncertainty. */
LBFGSERR_OUTOFINTERVAL,
/** A logic error occurred; alternatively, the interval of uncertainty became too small. */
LBFGSERR_INCORRECT_TMINMAX, // -1009
/** The function value became NaN or Inf. */
LBFGSERR_INVALID_FUNCVAL,
/** A rounding error occurred; alternatively, no line-search step satisfies the sufficient decrease and curvature conditions. */
LBFGSERR_ROUNDING_ERROR,
/** The line-search step became smaller than lbfgs_parameter_t::min_step. */
LBFGSERR_MINIMUMSTEP,
/** The line-search step became larger than lbfgs_parameter_t::max_step. */
LBFGSERR_MAXIMUMSTEP,
/** The line-search routine reaches the maximum number of evaluations. */
LBFGSERR_MAXIMUMLINESEARCH, // -1004
/** The algorithm routine reaches the maximum number of iterations. */
LBFGSERR_MAXIMUMITERATION,
/** Relative width of the interval of uncertainty is at most lbfgs_parameter_t::xtol. */
LBFGSERR_WIDTHTOOSMALL,
/** A logic error (negative line-search step) occurred. */
LBFGSERR_INVALIDPARAMETERS,
/** The current search direction increases the objective function value. */
LBFGSERR_INCREASEGRADIENT,
};
/**
* Callback interface to provide objective function and gradient evaluations.
*
* The lbfgs_optimize() function call this function to obtain the values of objective
* function and its gradients when needed. A client program must implement
* this function to evaluate the values of the objective function and its
* gradients, given current values of variables.
*
* @param instance The user data sent for lbfgs_optimize() function by the client.
* @param x The current values of variables.
* @param g The gradient vector. The callback function must compute
* the gradient values for the current variables.
* @param n The number of variables.
* @retval double The value of the objective function for the current
* variables.
*/
typedef double (*lbfgs_evaluate_t)(void *instance,
const double *x,
double *g,
const int n);
/**
* Callback interface to provide an upper bound at the beginning of current linear search.
*
* The lbfgs_optimize() function call this function to obtain the values of the
* upperbound of the stepsize to search in, provided with the beginning values of
* variables before the linear search, and the current step vector (can be descent direction).
* A client program can implement this function for more efficient linesearch. Any step
* larger than this bound should not be considered. For example, it has a very large or even
* inf function value. Note that the function value at the provided bound should be FINITE!
* If it is not used, just set it NULL or nullptr.
*
* @param instance The user data sent for lbfgs_optimize() function by the client.
* @param xp The values of variables before current line search.
* @param d The step vector. It can be the descent direction.
* @param n The number of variables.
* @retval double The upperboud of the step in current line search routine,
* such that stpbound*d is the maximum reasonable step.
*/
typedef double (*lbfgs_stepbound_t)(void *instance,
const double *xp,
const double *d,
const int n);
/**
* Callback interface to receive the progress of the optimization process.
*
* The lbfgs_optimize() function call this function for each iteration. Implementing
* this function, a client program can store or display the current progress
* of the optimization process. If it is not used, just set it NULL or nullptr.
*
* @param instance The user data sent for lbfgs_optimize() function by the client.
* @param x The current values of variables.
* @param g The current gradient values of variables.
* @param fx The current value of the objective function.
* @param xnorm The Euclidean norm of the variables.
* @param gnorm The Euclidean norm of the gradients.
* @param step The line-search step used for this iteration.
* @param n The number of variables.
* @param k The iteration count.
* @param ls The number of evaluations called for this iteration.
* @retval int Zero to continue the optimization process. Returning a
* non-zero value will cancel the optimization process.
*/
typedef int (*lbfgs_progress_t)(void *instance,
const double *x,
const double *g,
const double fx,
const double xnorm,
const double gnorm,
const double step,
int n,
int k,
int ls);
/**
* Callback data struct
*/
struct callback_data_t {
int n;
void *instance;
lbfgs_evaluate_t proc_evaluate;
lbfgs_stepbound_t proc_stepbound;
lbfgs_progress_t proc_progress;
};
/**
* Iteration data struct
*/
struct iteration_data_t {
double alpha;
double *s; /* [n] */
double *y; /* [n] */
double ys; /* vecdot(y, s) */
};
继续注释