Edit: It now runs fine - I had pasted a correction of a typo that I had not yet run... Thanks!
Original question:
With python / numpy / scipy, I would like to minimize a function f
, which depends on several additional parameters c_1, c_2..., c_N
. As these are many: is there a possibility, as is with matlab's fminsearch
, to pass not only a tuple as additional arguments, but an arbitrary object, such as a class? I imagine something like:
from scipy import optimize as opt
def banana(x,s):
return 100*(x[1]-s.c)**2+(1-x[0])**2
class s:
pass
s.c = 55
xopt, fopt, iter, funcalls, warnflag \
= opt.fmin(func=banana, x0=np.array([-1.2,1]),args=(s,), xtol=0.0001,ftol=0.00001, full_output = True)
The code above yields "AttributeError: 'int' object has no attribute 'c'
", which I understand from the spec of the arguments being a tuple.
Thanks!