vnl_brent.cxx
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_brent.cxx
2 
3 #include <cassert>
4 #include "vnl_brent.h"
6 
8  : vnl_brent_minimizer( *functor )
9 {
10 }
11 
12 vnl_brent::~vnl_brent() = default;
13 
14 double vnl_brent::minimize_given_bounds(double ax, double bx, double cx,
15  double tol,
16  double *xmin)
17 {
18  assert( xmin != nullptr );
19  this->set_x_tolerance( tol );
20  *xmin = vnl_brent_minimizer::minimize_given_bounds( ax, bx, cx );
22 }
23 
24 double vnl_brent::minimize_given_bounds_and_1st_f(double ax, double bx,
25  double fb, double cx,
26  double tol, double *xmin)
27 {
28  assert( xmin != nullptr );
29  this->set_x_tolerance( tol );
32 }
33 
34 
35 void vnl_brent::bracket_minimum(double *ax, double *bx, double *cx)
36 {
37  double fa, fb, fc;
38  bracket_minimum(ax,bx,cx,&fa,&fb,&fc);
39 }
40 
41 void vnl_brent::bracket_minimum(double *ax, double *bx, double *cx,
42  double *fa, double *fb, double *fc)
43 {
44  vnl_bracket_minimum( *f_, *cx, *bx, *ax, *fc, *fb, *fa );
45 }
46 
47 
48 double vnl_brent::minimize(double x)
49 {
50  double ax=x-1.0;
51  double xx=x+1.0;
52  double bx = 0.0;
53  double fa,fx,fb;
54  bracket_minimum(&ax,&xx,&bx,&fa,&fx,&fb);
55  minimize_given_bounds(bx,xx,ax,ftol,&x);
56  return x;
57 }
An object that represents a function from R^n -> R.
double minimize(double ax)
Find a minimum of f(x) near to ax.
Definition: vnl_brent.cxx:48
double minimize_given_bounds(double ax, double bx, double cx, double tol, double *xmin)
Find the minimum value of f(x) within a<= x <= c.
Definition: vnl_brent.cxx:14
double minimize_given_bounds_and_one_f(double ax, double bx, double cx, double fb)
Find the minimum value of f(x) within a<= x <= c.
double minimize_given_bounds(double ax, double bx, double cx)
Find the minimum value of f(x) within a<= x <= c.
void vnl_bracket_minimum(vnl_cost_function &fn, double &a, double &b, double &c, double &fa, double &fb, double &fc)
Given initial values a and b, find bracket a<b<c s.t. f(a)>f(b)<f(c).
Brent 1D minimizer.
double ftol
Termination tolerance on F (sum of squared residuals)
double minimize_given_bounds_and_1st_f(double ax, double bx, double fb, double cx, double tol, double *xmin)
Save time over minimize_given_bounds() if you know f(b).
Definition: vnl_brent.cxx:24
vnl_cost_function * f_
Function to bracket a minimum.
void bracket_minimum(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc)
Given distinct points ax, and bx, find a bracket for the minimum.
Definition: vnl_brent.cxx:41
vnl_brent(vnl_cost_function *functor)
Definition: vnl_brent.cxx:7
~vnl_brent() override
double f_at_last_minimum() const
Function evaluation at value returned by minimize(x).
void set_x_tolerance(double v)
Set the convergence tolerance on X.