]> gitweb.michael.orlitzky.com - octave.git/blobdiff - optimization/step_length_positive_definite.m
Refix the non-negativity of denom in step_length_positive_definite().
[octave.git] / optimization / step_length_positive_definite.m
index ad63956cfa603c097084d15291962c552d6c9d7a..b9fe48efa52144ab6c6fdb05f06cf3c5e8b6a9dd 100644 (file)
@@ -32,5 +32,14 @@ function alpha = step_length_positive_definite(g, Q, p)
   %
   % All vectors are assumed to be *column* vectors.
   %
-  alpha = -(g' * p)/(p' * Q * p);
+  denom = (p' * Q * p);
+
+  % denom is non-negative, since it's a Q-norm. No need to abs() it.
+  if (denom < eps)
+    % Catch divide-by-zeros. If denom is effectively zero, set it to
+    % something tiny instead. This trick is also used in the PCGM.
+    denom = eps;
+  end
+
+  alpha = (g' * g)/denom;
 end