12 static const double COMPL_GOLD = 0.381966011250105152;
13 static const double EPS = 1e-8;
76 double m = 0.5*(ax+cx);
77 double tol = EPS*std::fabs(x)+
xtol;
84 while (std::fabs(x-
m)>(tol2-0.5*(cx-ax)))
87 double p=0.0,q=0.0,r=0.0;
93 p = (x-
v)*q - (x-w)*r;
95 if (q>0) p*=-1.0;
else q*=-1.0;
99 if (std::fabs(p)<std::fabs(0.5*q*r) &&
100 p>(q*(ax-x)) && p<(q*(cx-x)) )
107 if (u-ax<tol2 || cx-u<tol2) d = (x<
m?tol:-tol);
117 if (std::fabs(d)>=tol)
131 if (u<x) cx=x;
else ax=x;
138 if (u<x) ax=u;
else cx=u;
144 else if (fu<=fv ||
v==x ||
v==w) {
v=u; fv=fu; }
149 tol = EPS*std::fabs(x)+
xtol;
165 double fa,
double fb,
double fc)
182 if (fa<fc) { w=ax; fw=fa;
v=cx; fv=fc; }
183 else { w=cx; fw=fc;
v=ax; fv=fa; }
187 double m = 0.5*(ax+cx);
188 double tol = EPS*std::fabs(x)+
xtol;
195 while (std::fabs(x-
m)>(tol2-0.5*(cx-ax)))
198 double p=0.0,q=0.0,r=0.0;
199 if (std::fabs(e)>tol)
204 p = (x-
v)*q - (x-w)*r;
206 if (q>0) p*=-1.0;
else q*=-1.0;
210 if (std::fabs(p)<std::fabs(0.5*q*r) &&
211 p>(q*(ax-x)) && p<(q*(cx-x)) )
218 if (u-ax<tol2 || cx-u<tol2) d = (x<
m?tol:-tol);
228 if (std::fabs(d)>=tol)
242 if (u<x) cx=x;
else ax=x;
249 if (u<x) ax=u;
else cx=u;
255 else if (fu<=fv ||
v==x ||
v==w) {
v=u; fv=fu; }
260 tol = EPS*std::fabs(x)+
xtol;
An object that represents a function from R^n -> R.
double f_at_last_minimum_
Function evaluation at value returned by minimize(x).
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.
bool set_size(size_t n)
Resize to n elements.
double minimize_given_bounds_and_all_f(double ax, double bx, double cx, double fa, double fb, double fc)
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.
double f(vnl_vector< double > const &x) override
The main function. Given the parameter vector x, compute the value of f(x).
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).
double operator()(double x)
double minimize(double ax)
Find a minimum of f(x) near to ax.
~vnl_brent_minimizer() override
Function to bracket a minimum.
vnl_decnum max(vnl_decnum const &x, vnl_decnum const &y)
double xtol
Termination tolerance on X (solution vector)
vnl_brent_minimizer(vnl_cost_function &functor)
vnl_decnum min(vnl_decnum const &x, vnl_decnum const &y)
vnl_brent_minimizer_func(vnl_cost_function &fn)
void set_x_tolerance(double v)
Set the convergence tolerance on X.