[SciPy-User] optimize.leastsq and improper input parameters

ms devicerandom@gmail....
Thu Jul 8 18:13:49 CDT 2010


On 08/07/10 21:50, josef.pktd@gmail.com wrote:
> On Thu, Jul 8, 2010 at 1:46 PM, ms<devicerandom@gmail.com>  wrote:

>> massimo@boltzmann:~/work$ python test_norm_leastsq.py
>> Traceback (most recent call last):
>>    File "test_norm_leastsq.py", line 44, in<module>
>>      minimize(x,y,[1,2])
>>    File "test_norm_leastsq.py", line 41, in minimize
>>      i = opt.leastsq(f_to_minimize, p0, args)
>>    File "/usr/lib/python2.6/dist-packages/scipy/optimize/minpack.py",
>> line 300, in leastsq
>>      raise errors[info][1], errors[info][0]
>> TypeError: Improper input parameters.
>>
>> The funny thing is that it worked *before* I messed with the thing to
>> simplify the function-choosing mechanism (before I had N different
>> functions for each combination of fixed/nonfixed params, now I just have
>> two and I fix stuff *inside* the function), and I can't see however how
>> can this be different. Also, the example above leaves me perplexed -it
>> seems leastsq simply doesn't want two-variable functions to be minimized
>> in this case. Any hint?
>
>
> change in def f_to_minimize(pars,args):
>
>      #calculate squared residuals
> ##    resid = [(i-j)**2 for i,j in zip(y,y_estimate)]
> ##    return sum(resid)
>      return [(i-j) for i,j in zip(y,y_estimate)]
>
> leastsq does the squared sum itself, and needs as return of the
> function the vector of residuals
>
> docstring:
> func – A Python function or method which takes at least one
> (possibly length N vector) argument and returns M floating point numbers
>
> with only one parameter leastsq assumes you have one observation and
> one parameter N=1, M=1
>
> this is what I get running the changed script
> (array([-12.,   9.]), 2)
>
> I didn't check anything else in your script.
>
> Josef

Thanks! I didn't notice that leastsq was so clever :)
I tried quickly now and I still have some trouble, but seems unrelated 
to the issue, tomorrow I'll see if it's definitely fixed.

thanks again,

m.


More information about the SciPy-User mailing list