13 using std::numeric_limits;
29 template<
class Functor,
class Precision>
Vector<2, Precision> brent_line_search(Precision a, Precision x, Precision b, Precision fx,
const Functor& func,
int maxiterations, Precision tolerance = sqrt(numeric_limits<Precision>::epsilon()), Precision epsilon = numeric_limits<Precision>::epsilon())
37 const Precision g = (3.0 - sqrt(5))/2;
54 Precision w=x, v=x, fw=fx, fv=fx;
59 while(
abs(b-a) > (
abs(a) +
abs(b)) * tolerance + epsilon && i < maxiterations)
63 const Precision xm = (a+b)/2;
66 const Precision tol1 =
abs(x)*tolerance + epsilon;
72 if(
abs(e) > tol1 && w != v)
81 const Precision fxw = fw - fx;
82 const Precision fxv = fv - fx;
83 const Precision xw = w-x;
84 const Precision xv = v-x;
93 const Precision p = fxv*xw*xw - fxw*xv*xv;
94 const Precision q = 2*(fxv*xw - fxw*xv);
100 if(q == 0 || x + p/q < a || x+p/q > b ||
abs(p/q) >
abs(e/2))
130 const Precision u = x+d;
132 const Precision fu = func(u);
158 if(fu <= fw || w == x)
164 else if(fu <= fv || v==x || v == w)
Everything lives inside this namespace.
Vector< 2, Precision > brent_line_search(Precision a, Precision x, Precision b, Precision fx, const Functor &func, int maxiterations, Precision tolerance=sqrt(numeric_limits< Precision >::epsilon()), Precision epsilon=numeric_limits< Precision >::epsilon())
Vector< 1 > makeVector(double x1)