📄 min.texi
字号:
@cindex optimization, see minimization@cindex maximization, see minimization@cindex minimization, one-dimensional@cindex finding minima@cindex non-linear functions, minimizationThis chapter describes routines for finding minima of arbitraryone-dimensional functions. The library provides low level componentsfor a variety of iterative minimizers and convergence tests. These can becombined by the user to achieve the desired solution, with full accessto the intermediate steps of the algorithms. Each class of methods usesthe same framework, so that you can switch between minimizers at runtimewithout needing to recompile your program. Each instance of a minimizerkeeps track of its own state, allowing the minimizers to be used inmulti-threaded programs.The header file @file{gsl_min.h} contains prototypes for theminimization functions and related declarations. To use the minimizationalgorithms to find the maximum of a function simply invert its sign.@menu* Minimization Overview:: * Minimization Caveats:: * Initializing the Minimizer:: * Providing the function to minimize:: * Minimization Iteration:: * Minimization Stopping Parameters:: * Minimization Algorithms:: * Minimization Examples:: * Minimization References and Further Reading:: @end menu@node Minimization Overview@section Overview@cindex minimization, overviewThe minimization algorithms begin with a bounded region known to containa minimum. The region is described by an lower bound @math{a} and anupper bound @math{b}, with an estimate of the minimum @math{x}.@iftex@sp 1@center @image{min-interval}@end iftex@noindentThe value of the function at @math{x} must be less than the value of thefunction at the ends of the interval,@iftex@tex$$f(a) > f(x) < f(b)$$@end tex@end iftex@ifinfo@examplef(a) > f(x) < f(b)@end example@end ifinfo@noindentThis condition guarantees that a minimum is contained somewhere withinthe interval. On each iteration a new point @math{x'} is selected usingone of the available algorithms. If the new point is a better estimateof the minimum, @math{f(x') < f(x)}, then the current estimate of theminimum @math{x} is updated. The new point also allows the size of thebounded interval to be reduced, by choosing the most compact set ofpoints which satisfies the constraint @math{f(a) > f(x) < f(b)}. Theinterval is reduced until it encloses the true minimum to a desiredtolerance. This provides a best estimate of the location of the minimumand a rigorous error estimate.Several bracketing algorithms are available within a single framework.The user provides a high-level driver for the algorithm, and thelibrary provides the individual functions necessary for each of thesteps. There are three main phases of the iteration. The steps are,@itemize @bullet@iteminitialize minimizer state, @var{s}, for algorithm @var{T}@itemupdate @var{s} using the iteration @var{T}@itemtest @var{s} for convergence, and repeat iteration if necessary@end itemize@noindentThe state for the minimizers is held in a @code{gsl_min_fminimizer}struct. The updating procedure uses only function evaluations (notderivatives).@node Minimization Caveats@section Caveats@cindex Minimization, caveatsNote that minimization functions can only search for one minimum at atime. When there are several minima in the search area, the firstminimum to be found will be returned; however it is difficult to predictwhich of the minima this will be. @emph{In most cases, no error will bereported if you try to find a minimum in an area where there is morethan one.}With all minimization algorithms it can be difficult to determine thelocation of the minimum to full numerical precision. The behavior of thefunction in the region of the minimum @math{x^*} can be approximated bya Taylor expansion,@iftex@tex$$y = f(x^*) + {1 \over 2} f''(x^*) (x - x^*)^2$$@end tex@end iftex@ifinfo@exampley = f(x^*) + (1/2) f''(x^*) (x - x^*)^2@end example@end ifinfo@noindentand the second term of this expansion can be lost when added to thefirst term at finite precision. This magnifies the error in locating@math{x^*}, making it proportional to @math{\sqrt \epsilon} (where@math{\epsilon} is the relative accuracy of the floating point numbers).For functions with higher order minima, such as @math{x^4}, themagnification of the error is correspondingly worse. The best that canbe achieved is to converge to the limit of numerical accuracy in thefunction values, rather than the location of the minimum itself.@node Initializing the Minimizer@section Initializing the Minimizer@deftypefun {gsl_min_fminimizer *} gsl_min_fminimizer_alloc (const gsl_min_fminimizer_type * @var{T})This function returns a pointer to a a newly allocated instance of aminimizer of type @var{T}. For example, the following codecreates an instance of a golden section minimizer,@exampleconst gsl_min_fminimizer_type * T = gsl_min_fminimizer_goldensection;gsl_min_fminimizer * s = gsl_min_fminimizer_alloc (T);@end exampleIf there is insufficient memory to create the minimizer then the functionreturns a null pointer and the error handler is invoked with an errorcode of @code{GSL_ENOMEM}.@end deftypefun@deftypefun int gsl_min_fminimizer_set (gsl_min_fminimizer * @var{s}, gsl_function * @var{f}, double @var{minimum}, double @var{x_lower}, double @var{x_upper})This function sets, or resets, an existing minimizer @var{s} to use thefunction @var{f} and the initial search interval [@var{x_lower},@var{x_upper}], with a guess for the location of the minimum@var{minimum}.If the interval given does not contain a minimum, then the functionreturns an error code of @code{GSL_FAILURE}.@end deftypefun@deftypefun int gsl_min_fminimizer_set_with_values (gsl_min_fminimizer * @var{s}, gsl_function * @var{f}, double @var{minimum}, double @var{f_minimum}, double @var{x_lower}, double @var{f_lower}, double @var{x_upper}, double @var{f_upper})This function is equivalent to @code{gsl_min_fminimizer_set} but usesthe values @var{f_minimum}, @var{f_lower} and @var{f_upper} instead ofcomputing @code{f(minimum)}, @code{f(x_lower)} and @code{f(x_upper)}.@end deftypefun@deftypefun void gsl_min_fminimizer_free (gsl_min_fminimizer * @var{s})This function frees all the memory associated with the minimizer@var{s}.@end deftypefun@deftypefun {const char *} gsl_min_fminimizer_name (const gsl_min_fminimizer * @var{s})This function returns a pointer to the name of the minimizer. For example,@exampleprintf("s is a '%s' minimizer\n", gsl_min_fminimizer_name (s));@end example@noindentwould print something like @code{s is a 'brent' minimizer}.@end deftypefun@node Providing the function to minimize@section Providing the function to minimize@cindex minimization, providing a function to minimizeYou must provide a continuous function of one variable for theminimizers to operate on. In order to allow for general parameters thefunctions are defined by a @code{gsl_function} data type(@pxref{Providing the function to solve}).@node Minimization Iteration@section IterationThe following functions drive the iteration of each algorithm. Eachfunction performs one iteration to update the state of any minimizer of thecorresponding type. The same functions work for all minimizers so thatdifferent methods can be substituted at runtime without modifications tothe code.@deftypefun int gsl_min_fminimizer_iterate (gsl_min_fminimizer * @var{s})This function performs a single iteration of the minimizer @var{s}. If theiteration encounters an unexpected problem then an error code will bereturned,@table @code@item GSL_EBADFUNCthe iteration encountered a singular point where the function evaluatedto @code{Inf} or @code{NaN}.@item GSL_FAILUREthe algorithm could not improve the current best approximation orbounding interval.@end table@end deftypefunThe minimizer maintains a current best estimate of the minimum at alltimes, and the current interval bounding the minimum. This informationcan be accessed with the following auxiliary functions,@deftypefun double gsl_min_fminimizer_minimum (const gsl_min_fminimizer * @var{s})This function returns the current estimate of the minimum for the minimizer@var{s}.@end deftypefun@deftypefun double gsl_interval gsl_min_fminimizer_x_upper (const gsl_min_fminimizer * @var{s})@deftypefunx double gsl_interval gsl_min_fminimizer_x_lower (const gsl_min_fminimizer * @var{s})These functions return the current upper and lower bound of the intervalfor the minimizer @var{s}.@end deftypefun
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -