python - How can i use a function with "variable" constants in scipy.optimize? -


how can use "variable" constants in scipy.optimize functions? trying create iterative optimisation algorithm, updates parameters in objective function after each optimisation run.

to use simple example of want do:

from scipy import optimize opt  def f(x, r):     return r * (x[0]**2 + x[1]**3)  r = 0.1 # initial r value y = [] y.append([2,2]) # initial point  in range(0,10):     y.append(opt.fmin(f, y[i])) # how can include 'r' in line??     r = some_function_to_update_r(r) 

any appreciated

edit:
re-declare objective function each time optimise? make loop instead?

for in range(0,10):     def f_temp(x_temp):         return f(x_temp,r)     y.append(opt.fmin(f_temp, y[i]))     r = some_function_to_update_r(r) 

or there better way?

fmin supports optional args argument, representing tuple of additional arguments passed function you're trying optimize:

y.append(opt.fmin(f, y[i], args=(r,))) 

this explained in documentation fmin; should habit of checking documentation when want figure out how something.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -