python - having trouble using scipy.optimize.leastsq -
everything else works fine when use leasesq function pydev editor have error says undefined variable import: leastsq going on here?
the code mit's python cost model timing.py @ url: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/readings/python-cost-model/timing.py , leastsq part in function:
def fit2(a,b): """ relative error minimizer """ def f(x): assert len(x) == len(a[0]) resids = [] in range(len(a)): sum = 0.0 j in range(len(a[0])): sum += a[i][j]*x[j] relative_error = (sum-b[i])/b[i] resids.append(relative_error) return resids ans = scipy.optimize.leastsq(f,[0.0]*len(a[0])) # print "ans:",ans if len(a[0])==1: x = [ans[0]] else: x = ans[0] resids = sum([r*r r in f(x)]) return (x,resids,0,0)
it seems me you're giving lsq-function 2 keyword arguments, while requires three. you're supplying function, initial values, not actual values on lsq made?
Comments
Post a Comment