# [SciPy-User] problem with the fmin function

Oleksandr Huziy guziy.sasha@gmail....
Mon Apr 30 09:01:20 CDT 2012

```Try powell method, it could be faster.
http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_powell.html#scipy.optimize.fmin_powell

you may also check out others here
http://docs.scipy.org/doc/scipy/reference/optimize.html

Cheers

--
Oleksandr

2012/4/30 servant mathieu <servant.mathieu@gmail.com>

> Hi Oleksandr,
>
> Thank you very much, it works perfectly.
> The simplex (Nelder-Mead) routine is rather slow. I'm looking for an
> alternative, faster algorithm which could do the job (minimization of a
> chi-square) as well. Any idea?
> Cheers,
> Mathieu
>
>
>
>
> 2012/4/30 Oleksandr Huziy <guziy.sasha@gmail.com>
>
>> Hi, error message says it needs 5 input arguments and you are giving one
>> (the list but still only one), you could change your chis function
>>
>> def chis (x):
>>               a, ter , v , sda , rd = x
>>               observed data
>>               simulated_data = spotdiffusion ( a, ter , v , sda , rd)
>>               do chi-square computations
>>               returns the chi-square value (float)
>>
>> cheers
>>
>>
>> --
>> Oleksandr Huziy
>>
>> 2012/4/30 servant mathieu <servant.mathieu@gmail.com>
>>
>>> Dear scipy users,
>>>
>>> I'm trying to minimize a chi-square value by a simplex routine. My code
>>> contains two functions: the first one, called spotdiffusion(a, ter , v ,
>>> sda , rd) generates some simulated data for a given set of parameter
>>> values. The second function, called chis ( a, ter , v , sda , rd), computes
>>> a chi-square value from the comparison of observed and simulated data, for
>>> a given set of parameter values. To do so, the chis function calls the
>>> spotdiffusion one. Here is a simplified structure of my code:
>>>
>>> def spotdiffusion (a, ter , v , sda , rd):
>>>              do simulation computations
>>>              returns an array of simulated data
>>>
>>> def chis (a, ter , v , sda , rd):
>>>               observed data
>>>               simulated_data = spotdiffusion ( a, ter , v , sda , rd)
>>>               do chi-square computations
>>>               returns the chi-square value (float)
>>>
>>> Now I want now to find a, ter, v, sda and rda values which minimize the
>>> chi-square. Here is my attempt:
>>>
>>> x0 = np.array ([0.11,0.25,0.35, 1.7, 0.017]) ####initial guess
>>> xopt = fmin (chis, x0, maxiter=300)
>>>
>>> However, python returns an error:
>>> Traceback (most recent call last):
>>>   File "<ipython console>", line 1, in <module>
>>>   File
>>> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py",
>>> line 128, in runfile
>>>     execfile(filename, glbs)
>>>   File "C:\Users\mathieu\Desktop\modeling\spotlight diffusion
>>> model\fitting_spotlight.py", line 246, in <module>
>>>     xopt = fmin (chis, x0, maxiter=300)
>>>   File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line
>>> 257, in fmin
>>>     fsim[0] = func(x0)
>>>   File "C:\Python27\lib\site-packages\scipy\optimize\optimize.py", line
>>> 176, in function_wrapper
>>>     return function(x, *args)
>>> TypeError: chis() takes exactly 5 arguments (1 given)
>>>
>>> I don't understand where is my mistake. Any help would be appreciated!
>>>
>>> Cheers,
>>> Mathieu
>>>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>>>
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120430/7face3be/attachment.html
```