]> gitweb.michael.orlitzky.com - octave.git/commitdiff
Simplify (subjectively) the steepest descent loop.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 25 Mar 2013 18:51:59 +0000 (14:51 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 25 Mar 2013 18:51:59 +0000 (14:51 -0400)
optimization/steepest_descent.m

index 0a6475e4614c37822be1c36ce891c003aae6ca55..c0e88dd4e37f0989992dd98c119e611701df21ef 100644 (file)
@@ -58,14 +58,15 @@ function [x, k] = steepest_descent(g,  ...
 
     dk = -gk;
     alpha_k = step_size(xk);
 
     dk = -gk;
     alpha_k = step_size(xk);
-    xk = xk + (alpha_k * dk);
-    gk = g(xk);
+    x_next = xk + (alpha_k * dk);
 
     % We potentially just performed one more iteration than necessary
     % in order to simplify the loop. Note that due to the structure of
     % our loop, we will have k > max_iterations when we fail to
     % converge.
     k = k + 1;
 
     % We potentially just performed one more iteration than necessary
     % in order to simplify the loop. Note that due to the structure of
     % our loop, we will have k > max_iterations when we fail to
     % converge.
     k = k + 1;
+    xk = x_next;
+    gk = g(x_next);
   end
 
   x = xk;
   end
 
   x = xk;