Commit 48f3eb20 authored by Davis King's avatar Davis King

Added a check for division by zero to the conjugate gradient

optimization functions.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402406
parent 197b36eb
...@@ -527,8 +527,13 @@ namespace dlib ...@@ -527,8 +527,13 @@ namespace dlib
g2 = der(x); g2 = der(x);
const double temp = trans(g)*g;
// just stop if this value hits zero
if (std::abs(temp) < std::numeric_limits<double>::epsilon())
break;
// Use the Polak-Ribiere (4.1.12) conjugate gradient described by Fletcher on page 83 // Use the Polak-Ribiere (4.1.12) conjugate gradient described by Fletcher on page 83
double b = trans(g2-g)*g2/(trans(g)*g); double b = trans(g2-g)*g2/(temp);
s = -g2 + b*s; s = -g2 + b*s;
g.swap(g2); g.swap(g2);
...@@ -671,7 +676,12 @@ namespace dlib ...@@ -671,7 +676,12 @@ namespace dlib
g2 = derivative(f,derivative_eps)(x); g2 = derivative(f,derivative_eps)(x);
// Use the Polak-Ribiere (4.1.12) conjugate gradient described by Fletcher on page 83 // Use the Polak-Ribiere (4.1.12) conjugate gradient described by Fletcher on page 83
double b = trans(g2-g)*g2/(trans(g)*g); const double temp = trans(g)*g;
// just stop if this value hits zero
if (std::abs(temp) < std::numeric_limits<double>::epsilon())
break;
double b = trans(g2-g)*g2/(temp);
s = -g2 + b*s; s = -g2 + b*s;
g.swap(g2); g.swap(g2);
......
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