[SciPy-User] problem with scipy.optimize

Géraldine huth ghuth@hotmail...
Wed Mar 23 09:59:07 CDT 2011


Hi all,

I'm new to Python and I have some difficulties in using scipy optimization functions.

I would like to optimize a function f, and the calcul of this function requires the use of the hypergeometric and beta function. 

Scipy has his own hypergeometric and beta function (names hyp2f1 and beta) but, with my 
arguments, the calcul of for example hyp2f1(-400,9.0972,-788.90,1.0) returns "nan", while the mpmath hypergeometric function (also names hyp2f1) returns a number. (It's the same with the beta function) 

So I would like to use mpmath hyp2f1 and beta functions in the calcul of the function f but the problem is that the mpf type returned by mpmath function seems not to be compatible with scipy optimization function.

example with the use of fmin_cobyla function:


>>> g=array([0.5])
>>> fmin_cobyla(f, g, [constr1, constr2], rhoend=1e-7)  
 
capi_return is NULL
Call-back cb_calcfc_in__cobyla__user__routines failed.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/cobyla.py", line 96, in fmin_cobyla
    iprint=iprint, maxfun=maxfun)
  File "/usr/lib/python2.6/dist-packages/scipy/optimize/cobyla.py", line 88, in calcfc
    f = func(x, *args)
  File "<stdin>", line 13, in pnn
  File "/usr/lib/pymodules/python2.6/mpmath/functions/hypergeometric.py", line 249, in hyp2f1
    return ctx.hyper([a,b],[c],z,**kwargs)
  File "/usr/lib/pymodules/python2.6/mpmath/functions/hypergeometric.py", line 198, in hyper
    z = ctx.convert(z)
  File "/usr/lib/pymodules/python2.6/mpmath/ctx_mp_python.py", line 654, in convert
    return ctx._convert_fallback(x, strings)
  File "/usr/lib/pymodules/python2.6/mpmath/ctx_mp.py", line 544, in _convert_fallback
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from array([ 1.])


 What is the solution?


Thanks in advance

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110323/8e55f099/attachment-0001.html 


More information about the SciPy-User mailing list