From 869aa9110923894660efeea7bcdc71ec95db336d Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Thu, 17 Oct 2013 13:49:50 -0400 Subject: [PATCH] * fit_func(): Allow non-(numpy.ndarray) args for x, y, dy. * Documentation update. --- math/fitting/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/math/fitting/__init__.py b/math/fitting/__init__.py index b193374..134f89f 100644 --- a/math/fitting/__init__.py +++ b/math/fitting/__init__.py @@ -119,6 +119,14 @@ class Poly_order4(Poly_base): class fit_result(result_base): + """The basic values expected in fit_result are: + - xopt + - chi_square + + Optional values: + - funcalls + - xerr + """ pass def fit_func(Funct, Data=None, Guess=None, @@ -177,9 +185,14 @@ def fit_func(Funct, Data=None, Guess=None, global last_fit_rslt, last_chi_sqr from scipy.optimize import fmin, fmin_bfgs, leastsq, anneal # We want to minimize this error: - if Data != None: # an alternative way to specifying x and y + if Data != None: + # an alternative way to specifying x and y + Data = numpy.asarray(Data) y = Data[0] x = Data[1:] # possibly multidimensional! + else: + x = numpy.asarray(x) + y = numpy.asarray(y) if debug >= 10: print "Dimensionality of the domain is: ", len(x) @@ -233,7 +246,7 @@ def fit_func(Funct, Data=None, Guess=None, if w != None and dy != None: raise TypeError, "Only one of w or dy can be specified." if dy != None: - sqrtw = 1.0 / dy + sqrtw = 1.0 / numpy.asarray(dy) elif w != None: sqrtw = numpy.sqrt(w) else: