vnl_brent_minimizer.h
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_brent_minimizer.h
2 #ifndef vnl_brent_minimizer_h_
3 #define vnl_brent_minimizer_h_
4 //:
5 // \file
6 // \author Tim Cootes
7 // \date Feb 2007
8 //
9 // \verbatim
10 // Modifications
11 // \endverbatim
12 
13 #include <vnl/vnl_cost_function.h>
15 
16 #include <vnl/algo/vnl_algo_export.h>
17 
18 struct vnl_brent_data;
19 
20 //: Brent 1D minimizer
21 // Minimizes a 1D function using a cunning combination of golden section
22 // and parabolic interpolation. It does not require derivatives to be
23 // supplied. It is guaranteed to find a minimum, and generally works
24 // efficiently - ie using few function evaluations.
25 //
26 // This implementation is based on that described by R.P. Brent
27 // in Chapter 5 of "Algorithms for Minimization Without Derivatives", 1973.
28 // In particular, is a C++ translation of the ALGOL program given at
29 // the end of that chapter.
30 //
31 // Example usage:
32 // \verbatim
33 // // Create 1D cost function
34 // class my_cost_fn : public vnl_cost_function {
35 // my_cost_fn() : vnl_cost_function(1) {}
36 //
37 // double f(const vnl_vector<double>& x)
38 // { return (2 - x[0]) * (2 - x[0]) + 10; }
39 // };
40 //
41 // my_cost_fn f1;
42 // vnl_brent_minimizer brent(f1);
43 //
44 // double initial_x = 3.5;
45 // // Find the position of the minimum
46 // double x = brent.minimize(initial_x);
47 // double min_f = brent.f_at_last_minimum();
48 // \endverbatim
49 class VNL_ALGO_EXPORT vnl_brent_minimizer : public vnl_nonlinear_minimizer
50 {
51  protected:
53  //: Function evaluation at value returned by minimize(x)
55  public:
57  ~vnl_brent_minimizer() override;
58 
59  //: Find a minimum of f(x) near to ax.
60  // The evaluation of f(x) at the returned value can be obtained
61  // by a call to f_at_last_minimum();
62  double minimize(double ax);
63 
64  //: Function evaluation at value returned by minimize(x)
65  double f_at_last_minimum() const { return f_at_last_minimum_; }
66 
67  //: Find the minimum value of f(x) within a<= x <= c.
68  // \retval The position,x, of the minimum x.
69  // You need to provide a bracket for the minimum (a<b<c s.t. f(a)>f(b)<f(c).
70  // The tolerance can be set using prior call to set_x_tolerance(tol).
71  // Use f_at_last_minimum() to get function evaluation at the returned minima.
72  double minimize_given_bounds(double ax, double bx, double cx);
73 
74  //: Find the minimum value of f(x) within a<= x <= c.
75  // \retval The position,x, of the minimum x.
76  // You need to provide a bracket for the minimum (a<b<c s.t. f(a)>f(b)<f(c),
77  // and the known value at b (fb=f(b)).
78  // The tolerance can be set using prior call to set_x_tolerance(tol).
79  // Use f_at_last_minimum() to get function evaluation at the returned minima.
80  double minimize_given_bounds_and_one_f(double ax, double bx, double cx,
81  double fb);
82 
83  //: Find the minimum value of f(x) within a<= x <= c.
84  // \retval The position,x, of the minimum x.
85  // You need to provide a bracket for the minimum (a<b<c s.t. f(a)>f(b)<f(c)),
86  // and the values fa=f(a), fb=f(b), fc=f(c). This avoids recalculating
87  // them if you have them already. If you don't have them, it is
88  // probably better to use minimize_given_bounds(a,b,c).
89  //
90  // The tolerance can be set using prior call to set_x_tolerance(tol).
91  // Use f_at_last_minimum() to get function evaluation at the returned minima.
92  double minimize_given_bounds_and_all_f(double ax, double bx, double cx,
93  double fa, double fb, double fc);
94 };
95 
96 #endif // vnl_brent_minimizer_h_
An object that represents a function from R^n -> R.
double f_at_last_minimum_
Function evaluation at value returned by minimize(x).
Vector->Real function.
vnl_nonlinear_minimizer is a base class for nonlinear optimization.
Brent 1D minimizer.
vnl_cost_function * f_
Base class for nonlinear optimization.
double f_at_last_minimum() const
Function evaluation at value returned by minimize(x).