X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=optimization%2Fstep_length_positive_definite.m;h=5d3e8a0b2e92a1d4d4b54606ab9453b5a96be215;hp=b1e5c4802ec96ba749375c44337f9d91d7219e1d;hb=1a6f56b0dd6750649725b2fd07edb3fe0850a886;hpb=69d4adf22828f26858e89de560078e1b5ed1714a diff --git a/optimization/step_length_positive_definite.m b/optimization/step_length_positive_definite.m index b1e5c48..5d3e8a0 100644 --- a/optimization/step_length_positive_definite.m +++ b/optimization/step_length_positive_definite.m @@ -1,36 +1,43 @@ -function alpha = step_length_positive_definite(g, Q, p) - ## - ## Find the minimizer alpha of, - ## - ## phi(alpha) = f(x + alpha*p) - ## - ## where ``p`` is a descent direction, - ## - ## f(x) = (1/2) - - ## - ## and ``Q`` is positive-definite. - ## - ## The closed-form solution to this problem is given in Nocedal and - ## Wright, (3.55). - ## - ## INPUT: - ## - ## - ``g`` -- The gradient of f. - ## - ## - ``Q`` -- The positive-definite matrix in the definition of - ## ``f`` above. - ## - ## - ``p`` -- The direction in which ``f`` decreases. The line - ## along which we minimize f(x + alpha*p). - ## - ## OUTPUT: - ## - ## - ``alpha`` -- The value which causes ``f`` to decrease the - ## most. - ## - ## NOTES: - ## - ## All vectors are assumed to be *column* vectors. - ## - alpha = -(g' * p)/(p' * Q * p) +function alpha = step_length_positive_definite(g, Q) + % + % Find the minimizer alpha of, + % + % phi(alpha) = f(x + alpha*p) + % + % where ``p`` is a descent direction, + % + % f(x) = (1/2) - + % + % and ``Q`` is positive-definite. + % + % The closed-form solution to this problem is given in Nocedal and + % Wright, (3.55). The direction of steepest descent will always be + % the negative gradient direction; this simplified form is given in + % Guler. + % + % INPUT: + % + % - ``g`` -- The gradient of f at x. + % + % - ``Q`` -- The positive-definite matrix in the definition of + % ``f`` above. + % + % OUTPUT: + % + % - ``alpha`` -- The value which decreases ``f`` the most. + % + % NOTES: + % + % All vectors are assumed to be *column* vectors. + % + denom = (g' * Q * g); + + % 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