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

scipy-svn at scipy.org scipy-svn at scipy.org
Fri Feb 13 00:06:02 EST 2009


Author: oliphant
Date: 2009-02-12 23:05:59 -0600 (Thu, 12 Feb 2009)
New Revision: 5550

Modified:
   trunk/scipy/optimize/minpack.py
Log:
Fix curve_fit so that it can take an arbitrary number of predictor variables --- i.e. xdata can be k,N

Modified: trunk/scipy/optimize/minpack.py
===================================================================
--- trunk/scipy/optimize/minpack.py	2009-02-13 04:52:02 UTC (rev 5549)
+++ trunk/scipy/optimize/minpack.py	2009-02-13 05:05:59 UTC (rev 5550)
@@ -262,7 +262,7 @@
 
       fixed_point -- scalar and vector fixed-point finder
 
-      curve_fit -- find parameters for a 1-d curve-fitting problem. 
+      curve_fit -- find parameters for a curve-fitting problem. 
 
     """
     x0 = array(x0,ndmin=1)
@@ -331,13 +331,16 @@
 def curve_fit(f, xdata, ydata, p0=None, sigma=None, **kw):
     """Use non-linear least squares to fit a function, f, to data.
 
+    Assumes ydata = f(xdata,*params) + eps
+
     Parameters
     ----------
     f : callable
         The model function, f(x, *params).  It must take the independent
         variable as the first argument and the parameters to fit as 
         separate remaining arguments.
-    xdata : N-length sequence
+    xdata : An N-length sequence or an (k,N)-shaped array
+        for functions with k predictors. 
         The independent variable where the data is measured.
     ydata : N-length sequence
         The dependent data --- nominally f(xdata, *params)
@@ -399,8 +402,8 @@
     if ier != 1:
         raise RuntimeError, "Optimal parameters not found: " + mesg
 
-    if (len(xdata) > len(p0)):
-        s_sq = (func(popt, *args)**2).sum()/(len(xdata)-len(p0))
+    if (len(ydata) > len(p0)):
+        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




More information about the Scipy-svn mailing list