I'm trying to use scipy minimize
ssoln = scipy.optimize.minimize(HH, y0, jac=dHH, method='SLSQP', bounds=bnds,
constraints=cons)
where cons is obtained from a list of sage multivariate polynomials over the
same ring, constraint is the name of the list in question. If I hard code
cons = ({'type': 'eq', 'fun': lambda s: ((constraint[0])(*s))},
{'type': 'eq', 'fun': lambda s: ((constraint[1])(*s))},
{'type': 'eq', 'fun': lambda s: ((constraint[2])(*s))},
{'type': 'eq', 'fun': lambda s: ((constraint[3])(*s))})
everything works great (and cons seems to be a tuple of dict objects) but if I
try to automate with something like
cons=({'type': 'eq', 'fun': lambda s: ((constraint[0])(*s))},)
for ii in range(1,len(constraint)):
cons=cons+({'type': 'eq', 'fun': lambda s: ((constraint[ii])(*s))},)
or
cons=[]
for ii in range(len(constraint)):
cons.append({'type': 'eq', 'fun': lambda s: ((constraint[ii])(*s))})
cons=tuple(cons)
scipy.minimize fails with
Error in lines 1-1
Traceback (most recent call last):
File
"/projects/5511fe15-8085-4d1d-bdc7-c6bf6c99e693/.sagemathcloud/sage_server.py",
line 865, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File
"/projects/5511fe15-8085-4d1d-bdc7-c6bf6c99e693/.sagemathcloud/sage_salvus.py",
line 3026, in load
exec 'salvus.namespace["%s"] = sage.structure.sage_object.load(*__args,
**__kwds)'%t in salvus.namespace, {'__args':other_args, '__kwds':kwds}
File "<string>", line 1, in <module>
File "sage/structure/sage_object.pyx", line 916, in
sage.structure.sage_object.load
(build/cythonized/sage/structure/sage_object.c:10737)
File
"/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/misc/preparser.py",
line 1797, in load
exec(preparse_file(open(fpath).read()) + "\n", globals)
File "<string>", line 67, in <module>
File
"/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/scipy/optimize/_minimize.py",
line 435, in minimize
constraints, callback=callback, **options)
File
"/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/scipy/optimize/slsqp.py",
line 307, in _minimize_slsqp
meq = sum(map(len, [atleast_1d(c['fun'](x, *c['args'])) for c in
cons['eq']]))
File "<string>", line 59, in <lambda>
IndexError: list index out of range
I don't want to hard code the hand off to cons for each example where the
number of constraints and variables may change. Any suggestions? Thanks,
Happy Holidays,
Steve
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.