Commit 211f98b5 authored by Davis King's avatar Davis King

Tweaked find_min_box_constrained() so that the user can easily reuse

computations done in f() when computing der().
parent bfcae263
......@@ -330,6 +330,10 @@ namespace dlib
- returns f(#x).
- When calling f() and der(), the input passed to them will always be inside
the box constraints defined by x_lower and x_upper.
- When calling der(x), it will always be the case that the last call to f() was
made with the same x value. This means that you can reuse any intermediate
results from the previous call to f(x) inside der(x) rather than recomputing
them inside der(x).
!*/
// ----------------------------------------------------------------------------------------
......@@ -419,6 +423,10 @@ namespace dlib
- returns f(#x).
- When calling f() and der(), the input passed to them will always be inside
the box constraints defined by x_lower and x_upper.
- When calling der(x), it will always be the case that the last call to f() was
made with the same x value. This means that you can reuse any intermediate
results from the previous call to f(x) inside der(x) rather than recomputing
them inside der(x).
- Note that this function solves the maximization problem by converting it
into a minimization problem. Therefore, the values of f and its derivative
reported to the stopping strategy will be negated. That is, stop_strategy
......
......@@ -452,10 +452,12 @@ namespace dlib
if (d0 > 0 && alpha > 0)
alpha *= -1;
for (unsigned long iter = 0; iter < max_iter; ++iter)
unsigned long iter = 0;
while (true)
{
++max_iter;
const double val = f(alpha);
if (val <= f0 + alpha*rho*d0)
if (val <= f0 + alpha*rho*d0 || iter >= max_iter)
{
return alpha;
}
......@@ -472,7 +474,6 @@ namespace dlib
alpha *= step;
}
}
return alpha;
}
// ----------------------------------------------------------------------------------------
......
......@@ -217,10 +217,14 @@ namespace dlib
rule to decide when the search can stop.
- rho == the parameter of the sufficient decrease condition.
- max_iter == the maximum number of iterations allowable. After this many
evaluations of f() line_search() is guaranteed to terminate.
evaluations of f() backtracking_line_search() is guaranteed to terminate.
- The line search starts with the input alpha value and then backtracks until
it finds a good enough alpha value. Once found, it returns the alpha value
such that f(alpha) is significantly closer to the minimum of f than f(0).
- The returned value of alpha will always be the last value of alpha which was
passed to f(). That is, it will always be the case that the last call to f()
made by backtracking_line_search() was f(alpha) where alpha is the return
value from this function.
!*/
// ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment