[Scipy-svn] r5551 - trunk/scipy/optimize

scipy-svn@scip... scipy-svn@scip...
Thu Feb 12 23:17:34 CST 2009


Author: oliphant
Date: 2009-02-12 23:17:32 -0600 (Thu, 12 Feb 2009)
New Revision: 5551

Modified:
   trunk/scipy/optimize/minpack.py
Log:
Return inf for cov instead of None and check for None return from leastsq before multiplying.

Modified: trunk/scipy/optimize/minpack.py
===================================================================
--- trunk/scipy/optimize/minpack.py	2009-02-13 05:05:59 UTC (rev 5550)
+++ trunk/scipy/optimize/minpack.py	2009-02-13 05:17:32 UTC (rev 5551)
@@ -2,7 +2,7 @@
 
 from numpy import atleast_1d, dot, take, triu, shape, eye, \
                   transpose, zeros, product, greater, array, \
-                  all, where, isscalar, asarray
+                  all, where, isscalar, asarray, inf
 
 error = _minpack.error
 
@@ -397,18 +397,19 @@
     else:
         func = _weighted_general_function
         args += (1.0/asarray(sigma),)
-    popt, pcov, infodict, mesg, ier = leastsq(func, p0, args=args, full_output=1, **kw)
+    popt, pcov, infodict, mesg, ier = leastsq(func, p0, args=args, 
+                                              full_output=1, **kw)
     
     if ier != 1:
         raise RuntimeError, "Optimal parameters not found: " + mesg
 
-    if (len(ydata) > len(p0)):
+    if (len(ydata) > len(p0)) and pcov is not None:
         s_sq = (func(popt, *args)**2).sum()/(len(ydata)-len(p0))
         if sigma is not None:
             s_sq /= (args[-1]**2).sum()
         pcov = pcov * s_sq
     else:
-        pcov = None
+        pcov = inf
         
     return popt, pcov
 



More information about the Scipy-svn mailing list