X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=optimization%2Fstep_length_positive_definite.m;h=7e15a46513e7333a63f060385f353720745dbc29;hp=f6248f67b1dd40bf22ebdfed0947ddd6edbc47fa;hb=2a9c5d796e2f9d7b2b50739f61ef382623d977d6;hpb=b1a89e6359bfef7a07ffe49bc703b51ef47574a9 diff --git a/optimization/step_length_positive_definite.m b/optimization/step_length_positive_definite.m index f6248f6..7e15a46 100644 --- a/optimization/step_length_positive_definite.m +++ b/optimization/step_length_positive_definite.m @@ -1,36 +1,44 @@ 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 at x. - ## - ## - ``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); + % + % 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 at x. + % + % - ``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. + % + denom = (p' * Q * p); + + if (abs(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 = sign(denom)*eps; + end + + alpha = -(g' * p)/denom; end