From: Michael Orlitzky Date: Mon, 25 Mar 2013 18:51:59 +0000 (-0400) Subject: Simplify (subjectively) the steepest descent loop. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e8d03f4007b828784c68b1d4ff2ba8d644641cef;p=octave.git Simplify (subjectively) the steepest descent loop. --- diff --git a/optimization/steepest_descent.m b/optimization/steepest_descent.m index 0a6475e..c0e88dd 100644 --- a/optimization/steepest_descent.m +++ b/optimization/steepest_descent.m @@ -58,14 +58,15 @@ function [x, k] = steepest_descent(g, ... 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; + xk = x_next; + gk = g(x_next); end x = xk;