[Scipy-svn] r3170 - trunk/Lib/optimize

scipy-svn@scip... scipy-svn@scip...
Wed Jul 18 06:11:31 CDT 2007


Author: dmitrey.kroshko
Date: 2007-07-18 06:09:45 -0500 (Wed, 18 Jul 2007)
New Revision: 3170

Modified:
   trunk/Lib/optimize/optimize.py
Log:
bugfix with zerodevide in fmin_bfgs (ticket 377)


Modified: trunk/Lib/optimize/optimize.py
===================================================================
--- trunk/Lib/optimize/optimize.py	2007-07-18 08:43:20 UTC (rev 3169)
+++ trunk/Lib/optimize/optimize.py	2007-07-18 11:09:45 UTC (rev 3170)
@@ -22,7 +22,7 @@
 
 import numpy
 from numpy import atleast_1d, eye, mgrid, argmin, zeros, shape, \
-     squeeze, isscalar, vectorize, asarray, absolute, sqrt, Inf, asfarray
+     squeeze, isscalar, vectorize, asarray, absolute, sqrt, Inf, asfarray, isinf
 import linesearch
 
 # These have been copied from Numeric's MLab.py
@@ -707,11 +707,14 @@
         if (gnorm <= gtol):
             break
 
-        try:
-            rhok = 1 / (numpy.dot(yk,sk))
-        except ZeroDivisionError:
-            rhok = 1000.
+        try: # this was handled in numeric, let it remaines for more safety
+            rhok = 1.0 / (numpy.dot(yk,sk))
+        except ZeroDivisionError: 
+            rhok = 1000.0
             print "Divide-by-zero encountered: rhok assumed large"
+        if isinf(rhok): # this is patch for numpy
+            rhok = 1000.0
+            print "Divide-by-zero encountered: rhok assumed large"
         A1 = I - sk[:,numpy.newaxis] * yk[numpy.newaxis,:] * rhok
         A2 = I - yk[:,numpy.newaxis] * sk[numpy.newaxis,:] * rhok
         Hk = numpy.dot(A1,numpy.dot(Hk,A2)) + rhok * sk[:,numpy.newaxis] \



More information about the Scipy-svn mailing list