Mercurial > hg > octave-lyh
changeset 10392:b4e5dcf023c9
fix fminbnd termination tolerances
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 04 Mar 2010 15:19:23 +0100 |
parents | 59e34bcdff13 |
children | 7df8f8194c96 |
files | scripts/ChangeLog scripts/optimization/fminbnd.m |
diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2010-03-04 Jaroslav Hajek <highegg@gmail.com> + + * optimization/fminbnd.m: Fix termination tolerances. + 2010-03-02 Jaroslav Hajek <highegg@gmail.com> * polynomial/convn.m: Remove.
--- a/scripts/optimization/fminbnd.m +++ b/scripts/optimization/fminbnd.m @@ -83,7 +83,7 @@ info = 0; niter = 0; nfev = 0; - eps = eps (class (xmin + xmax)); + sqrteps = eps (class (xmin + xmax)); c = 0.5*(3-sqrt(5)); a = xmin; b = xmax; @@ -95,7 +95,10 @@ while (niter < maxiter && nfev < maxfev) xm = 0.5*(a+b); - tol = 2 * eps * abs (x) + tolx / 3; + ## FIXME: the golden section search can actually get closer than sqrt(eps)... + ## sometimes. Sometimes not, it depends on the function. This is the strategy + ## from the Netlib code. Something yet smarter would be good. + tol = 2 * sqrteps * abs (x) + tolx / 3; if (abs (x - xm) <= (2*tol - 0.5*(b-a))) info = 1; break; @@ -119,7 +122,7 @@ u = x + d; ## f must not be evaluated too close to ax or bx. - if ((u-a) < 2*tol && (b-u) < 2*tol) + if (min (u-a, b-u) < 2*tol) d = tol * (sign (xm - x) + (xm == x)); endif else