Commit b5467d0f authored by Davis King's avatar Davis King

Optimized the trust region solver a little bit.

parent 1a2a524a
...@@ -108,14 +108,32 @@ namespace dlib ...@@ -108,14 +108,32 @@ namespace dlib
continue; continue;
} }
using namespace blas_bindings;
p = -gg; p = -gg;
// Solve RR'*p = -g for p. // Solve RR'*p = -g for p.
using namespace blas_bindings;
// Solve R*q = -g for q where q = R'*p. // Solve R*q = -g for q where q = R'*p.
if (R.nr() == 2)
{
p(0) = p(0)/R(0,0);
p(1) = (p(1)-R(1,0)*p(0))/R(1,1);
}
else
{
triangular_solver(CblasLeft, CblasLower, CblasNoTrans, CblasNonUnit, R, p); triangular_solver(CblasLeft, CblasLower, CblasNoTrans, CblasNonUnit, R, p);
}
const T q_norm = length(p); const T q_norm = length(p);
// Solve R'*p = q for p. // Solve R'*p = q for p.
if (R.nr() == 2)
{
p(1) = p(1)/R(1,1);
p(0) = (p(0)-R(1,0)*p(1))/R(0,0);
}
else
{
triangular_solver(CblasLeft, CblasLower, CblasTrans, CblasNonUnit, R, p); triangular_solver(CblasLeft, CblasLower, CblasTrans, CblasNonUnit, R, p);
}
const T p_norm = length(p); const T p_norm = length(p);
// check if we are done. // check if we are done.
...@@ -233,6 +251,8 @@ namespace dlib ...@@ -233,6 +251,8 @@ namespace dlib
<< "\n\t radius: " << radius << "\n\t radius: " << radius
); );
const double initial_radius = radius;
typedef typename funct_model::column_vector T; typedef typename funct_model::column_vector T;
typedef typename T::type type; typedef typename T::type type;
typedef typename T::mem_manager_type mem_manager_type; typedef typename T::mem_manager_type mem_manager_type;
...@@ -280,7 +300,7 @@ namespace dlib ...@@ -280,7 +300,7 @@ namespace dlib
// something has gone horribly wrong if the radius has shrunk to zero. So just // something has gone horribly wrong if the radius has shrunk to zero. So just
// give up if that happens. // give up if that happens.
if (static_cast<type>(radius) <= std::numeric_limits<type>::min()) if (radius <= initial_radius*std::numeric_limits<double>::epsilon())
break; break;
} }
else else
......
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