[SciPy-User] problem with the fmin function

servant mathieu servant.mathieu@gmail....
Mon Apr 30 04:15:50 CDT 2012


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120430/05916edd/attachment.html 


More information about the SciPy-User mailing list