⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multimin.texi

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
@cindex minimization, multidimensionalThis chapter describes routines for finding minima of arbitrarymultidimensional functions.  The library provides low level componentsfor a variety of iterative minimizers and convergence tests.  These canbe combined by the user to achieve the desired solution, while providingfull access to the intermediate steps of the algorithms.  Each class ofmethods uses the same framework, so that you can switch betweenminimizers at runtime without needing to recompile your program.  Eachinstance of a minimizer keeps track of its own state, allowing theminimizers to be used in multi-threaded programs. The minimizationalgorithms can be used to maximize a function by inverting its sign.The header file @file{gsl_multimin.h} contains prototypes for theminimization functions and related declarations.  @menu* Multimin Overview::       * Multimin Caveats::        * Initializing the Multidimensional Minimizer::  * Providing a function to minimize::  * Multimin Iteration::      * Multimin Stopping Criteria::  * Multimin Algorithms::     * Multimin Examples::       * Multimin References and Further Reading::  @end menu@node Multimin Overview@section OverviewThe problem of multidimensional minimization requires finding a point@math{x} such that the scalar function,@tex\beforedisplay$$f(x_1, \dots, x_n)$$\afterdisplay@end tex@ifinfo@examplef(x_1, @dots{}, x_n)@end example@end ifinfo@noindenttakes a value which is lower than at any neighboring point. For smoothfunctions the gradient @math{g = \nabla f} vanishes at the minimum. Ingeneral there are no bracketing methods available for theminimization of @math{n}-dimensional functions.  All algorithmsproceed from an initial guess using a search algorithm which attemptsto move in a downhill direction. All algorithms making use of the gradient of the function perform aone-dimensional line minimisation along this direction until the lowestpoint is found to a suitable tolerance.  The search direction is thenupdated with local information from the function and its derivatives,and the whole process repeated until the true @math{n}-dimensionalminimum is found.The Nelder-Mead Simplex algorithm applies a different strategy.  Itmaintains @math{n+1} trial parameter vectors as the vertices of a@math{n}-dimensional simplex.  In each iteration step it tries toimprove the worst vertex by a simple geometrical transformation untilthe size of the simplex falls below a given tolerance.Several minimization algorithms are available within a singleframework. The user provides a high-level driver for the algorithms, andthe library 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@noindentEach iteration step consists either of an improvement to theline-minimisation in the current direction or an update to the searchdirection itself.  The state for the minimizers is held in a@code{gsl_multimin_fdfminimizer} struct or a@code{gsl_multimin_fminimizer} struct.@node Multimin Caveats@section Caveats@cindex Multimin, caveatsNote that the minimization algorithms can only search for one localminimum at a time.  When there are several local minima in the searcharea, the first minimum to be found will be returned; however it isdifficult to predict which of the minima this will be.  In most cases,no error will be reported if you try to find a local minimum in an areawhere there is more than one.It is also important to note that the minimization algorithms find localminima; there is no way to determine whether a minimum is a globalminimum of the function in question.@node Initializing the Multidimensional Minimizer@section Initializing the Multidimensional MinimizerThe following function initializes a multidimensional minimizer.  Theminimizer itself depends only on the dimension of the problem and thealgorithm and can be reused for different problems.@deftypefun {gsl_multimin_fdfminimizer *} gsl_multimin_fdfminimizer_alloc (const gsl_multimin_fdfminimizer_type *@var{T}, size_t @var{n})@deftypefunx {gsl_multimin_fminimizer *} gsl_multimin_fminimizer_alloc (const gsl_multimin_fminimizer_type *@var{T}, size_t @var{n})This function returns a pointer to a newly allocated instance of aminimizer of type @var{T} for an @var{n}-dimension function.  If thereis insufficient memory to create the minimizer then the function returnsa null pointer and the error handler is invoked with an error code of@code{GSL_ENOMEM}.@end deftypefun@deftypefun int gsl_multimin_fdfminimizer_set (gsl_multimin_fdfminimizer * @var{s}, gsl_multimin_function_fdf *@var{fdf}, const gsl_vector * @var{x}, double @var{step_size}, double @var{tol})This function initializes the minimizer @var{s} to minimize the function@var{fdf} starting from the initial point @var{x}.  The size of thefirst trial step is given by @var{step_size}.  The accuracy of the lineminimization is specified by @var{tol}.  The precise meaning of thisparameter depends on the method used.  Typically the line minimizationis considered successful if the gradient of the function @math{g} isorthogonal to the current search direction @math{p} to a relativeaccuracy of @var{tol}, where @c{$p\cdot g < tol |p| |g|$} @math{dot(p,g) < tol |p| |g|}.@deftypefunx int gsl_multimin_fminimizer_set (gsl_multimin_fminimizer * @var{s}, gsl_multimin_function *@var{f}, const gsl_vector * @var{x}, const gsl_vector * @var{step_size})This function initializes the minimizer @var{s} to minimize the function@var{f}, starting from the initial point@var{x}. The size of the initial trial steps is given in vector@var{step_size}. The precise meaning of this parameter depends on themethod used. @end deftypefun@deftypefun void gsl_multimin_fdfminimizer_free (gsl_multimin_fdfminimizer *@var{s})@deftypefunx void gsl_multimin_fminimizer_free (gsl_multimin_fminimizer *@var{s})This function frees all the memory associated with the minimizer@var{s}.@end deftypefun@deftypefun {const char *} gsl_multimin_fdfminimizer_name (const gsl_multimin_fdfminimizer * @var{s})@deftypefunx {const char *} gsl_multimin_fminimizer_name (const gsl_multimin_fminimizer * @var{s})This function returns a pointer to the name of the minimizer.  For example,@exampleprintf ("s is a '%s' minimizer\n",         gsl_multimin_fdfminimizer_name (s));@end example@noindentwould print something like @code{s is a 'conjugate_pr' minimizer}.@end deftypefun@node Providing a function to minimize@section Providing a function to minimizeYou must provide a parametric function of @math{n} variables for theminimizers to operate on.  You may also need to provide a routine whichcalculates the gradient of the function and a third routine whichcalculates both the function value and the gradient together.  In orderto allow for general parameters the functions are defined by thefollowing data type:@deftp {Data Type} gsl_multimin_function_fdfThis data type defines a general function of @math{n} variables withparameters and the corresponding gradient vector of derivatives,@table @code@item double (* f) (const gsl_vector * @var{x}, void * @var{params})this function should return the result@c{$f(x,\hbox{\it params})$}@math{f(x,params)} for argument @var{x} and parameters @var{params}.@item void (* df) (const gsl_vector * @var{x}, void * @var{params}, gsl_vector * @var{g})this function should store the @var{n}-dimensional gradient@c{$g_i = \partial f(x,\hbox{\it params}) / \partial x_i$}@math{g_i = d f(x,params) / d x_i} in the vector @var{g} for argument @var{x} and parameters @var{params}, returning an appropriate error code if thefunction cannot be computed.@item void (* fdf) (const gsl_vector * @var{x}, void * @var{params}, double * f, gsl_vector * @var{g})This function should set the values of the @var{f} and @var{g} as above,for arguments @var{x} and parameters @var{params}.  This function providesan optimization of the separate functions for @math{f(x)} and @math{g(x)} -- it is always faster to compute the function and its derivative at thesame time. @item size_t nthe dimension of the system, i.e. the number of components of thevectors @var{x}.@item void * paramsa pointer to the parameters of the function.@end table@end deftp@deftp {Data Type} gsl_multimin_functionThis data type defines a general function of @math{n} variables withparameters,@table @code@item double (* f) (const gsl_vector * @var{x}, void * @var{params})this function should return the result@c{$f(x,\hbox{\it params})$}@math{f(x,params)} for argument @var{x} and parameters @var{params}.@item size_t nthe dimension of the system, i.e. the number of components of thevectors @var{x}.@item void * paramsa pointer to the parameters of the function.@end table@end deftp@noindentThe following example function defines a simple paraboloid with twoparameters,@example/* Paraboloid centered on (dp[0],dp[1]) */doublemy_f (const gsl_vector *v, void *params)@{  double x, y;  double *dp = (double *)params;    x = gsl_vector_get(v, 0);  y = gsl_vector_get(v, 1);   return 10.0 * (x - dp[0]) * (x - dp[0]) +           20.0 * (y - dp[1]) * (y - dp[1]) + 30.0; @}/* The gradient of f, df = (df/dx, df/dy). */void my_df (const gsl_vector *v, void *params,        gsl_vector *df)@{  double x, y;  double *dp = (double *)params;    x = gsl_vector_get(v, 0);  y = gsl_vector_get(v, 1);   gsl_vector_set(df, 0, 20.0 * (x - dp[0]));  gsl_vector_set(df, 1, 40.0 * (y - dp[1]));@}/* Compute both f and df together. */void my_fdf (const gsl_vector *x, void *params,         double *f, gsl_vector *df) @{  *f = my_f(x, params);   my_df(x, params, df);@}@end example@noindentThe function can be initialized using the following code,@examplegsl_multimin_function_fdf my_func;double p[2] = @{ 1.0, 2.0 @}; /* center at (1,2) */my_func.f = &my_f;my_func.df = &my_df;my_func.fdf = &my_fdf;my_func.n = 2;my_func.params = (void *)p;@end example@node Multimin Iteration@section IterationThe following function drives the iteration of each algorithm.  Thefunction performs one iteration to update the state of the minimizer.The same function works for all minimizers so that different methods canbe substituted at runtime without modifications to the code.@deftypefun int gsl_multimin_fdfminimizer_iterate (gsl_multimin_fdfminimizer *@var{s})@deftypefunx int gsl_multimin_fminimizer_iterate (gsl_multimin_fminimizer *@var{s})These functions perform a single iteration of the minimizer @var{s}.  Ifthe iteration encounters an unexpected problem then an error code willbe returned.@end deftypefun@noindentThe minimizer maintains a current best estimate of the minimum at alltimes.  This information can be accessed with the following auxiliaryfunctions,@deftypefun {gsl_vector *} gsl_multimin_fdfminimizer_x (const gsl_multimin_fdfminimizer * @var{s})@deftypefunx {gsl_vector *} gsl_multimin_fminimizer_x (const gsl_multimin_fminimizer * @var{s})@deftypefunx double gsl_multimin_fdfminimizer_minimum (const gsl_multimin_fdfminimizer * @var{s})@deftypefunx double gsl_multimin_fminimizer_minimum (const gsl_multimin_fminimizer * @var{s})@deftypefunx {gsl_vector *} gsl_multimin_fdfminimizer_gradient (const gsl_multimin_fdfminimizer * @var{s})@deftypefunx double gsl_multimin_fminimizer_size (const gsl_multimin_fminimizer * @var{s})These functions return the current best estimate of the location of theminimum, the value of the function at that point, its gradient, and minimizer specific characteristic size for the minimizer @var{s}.@end deftypefun@deftypefun int gsl_multimin_fdfminimizer_restart (gsl_multimin_fdfminimizer *@var{s})This function resets the minimizer @var{s} to use the current point as anew starting point.@end deftypefun@node Multimin Stopping Criteria@section Stopping CriteriaA minimization procedure should stop when one of the followingconditions is true:@itemize @bullet@itemA minimum has been found to within the user-specified precision.@itemA user-specified maximum number of iterations has been reached.@itemAn error has occurred.@end itemize@noindentThe handling of these conditions is under user control.  The functionsbelow allow the user to test the precision of the current result.@deftypefun int gsl_multimin_test_gradient (const gsl_vector * @var{g}, double @var{epsabs})This function tests the norm of the gradient @var{g} against theabsolute tolerance @var{epsabs}. The gradient of a multidimensionalfunction goes to zero at a minimum. The test returns @code{GSL_SUCCESS}if the following condition is achieved,@tex\beforedisplay$$|g| < \hbox{\it epsabs}$$\afterdisplay@end tex@ifinfo@example|g| < epsabs@end example@end ifinfo@noindentand returns @code{GSL_CONTINUE} otherwise.  A suitable choice of@var{epsabs} can be made from the desired accuracy in the function for

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -