[SciPy-User] [SciPy-user] optimize fmin_cg parameter passing

Cameron Hayne cameron.hayne at dftmicrosystems.com
Fri Apr 13 03:13:41 EDT 2012


On 13-Apr-12, at 1:37 AM, aurora1625 wrote:
> I am new to Python and Scipy and I met a problem when trying to  
> optimize a
> function.
> My problem is:
> my f function has several parameters(datatype:array), it's like
> f = \sum lambda_i * phi_i + \zeta *(exp(lambda_i + \nu_i))
> this function is about lambda, so i get
> fprime = \sum phi_i + \zeta *(exp(lambda_i + \nu_i))
> I want to pass in an initial lambda value, but how can I pass in other
> parameter, phi, zeta and nu.
> I guess my function is about lambda, and the other parameters should  
> be
> constant and fixed, but I really don't know how to pass them in.


I'm not sure I have correctly understood what you are asking but it  
seems that what you want is a locally defined function.
In Python, you can define a function inside another function and the  
locally-defined function preserves all the values of variables used  
from the outer function.
For example:

def funcA(x, y):
	def funcB(z):
		return x**2 + y**2 + z**2
         print funcB(42)

In your case, you can make the inner function use the values of phi,  
zeta and nu,
and then pass the inner function to the optimization routine.

--
Cameron Hayne
macdev at hayne.net





More information about the SciPy-User mailing list