simple question/issue
def my_func(x,args):
a = x[0]
b = x[1]
return a*args[0] + a*args[1] + b*args[2]
import scipy.optimize as optimize
params = [1,2,3]
guess = [3,4]
bounds = [(1,5),(2,7)]
result = optimize.minimize(my_func, x0=guess, args=(params), method='SLSQP', bounds = bounds)
print(result)
print('done')
result = optimize.brute(my_func, args = tuple(params), ranges = bounds)
print(result)
The first optimisation runs fine. However, the second optimisation seems to have an issue with the number of input arguments? Not sure why:
fun: 9.0
jac: array([3., 3.])
message: 'Optimization terminated successfully'
nfev: 6
nit: 2
njev: 2
status: 0
success: True
x: array([1., 2.])
done
Traceback (most recent call last):
File "c:\Users\bob\Desktop\optimiser.py", line 15, in <module>
result = optimize.brute(my_func, args = tuple(params), ranges = bounds)
File "C:\Users\bob\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 3328, in brute
Jout = np.array(list(mapper(wrapped_func, grid)))
File "C:\Users\bob\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 3400, in __call__
return self.f(np.asarray(x).flatten(), *self.args)
TypeError: my_func() takes 2 positional arguments but 4 were given
I don't understand why it thinks 4 arguments are being given to my_func. Any ideas?
Cheers