0

I'm trying to maximize a (scalar) function in Python using scipy.minimize_scalar. Thought it would be more elegant to use lambda instead of defining a new function that's the negative of the given function. Unfortunately, it's giving a TypeError. Here's a simple example:

from scipy.optimize import minimize_scalar

def square(x):
    return -(x-1)**2

print(minimize_scalar(lambda x:-square(x),bounds=(0,None),method='bounded'))

Here's the error message I get:

TypeError: '>' not supported between instances of 'int' and 'NoneType'

What's wrong with this example code?

Thanks

J.D.
  • 139
  • 4
  • 14

1 Answers1

0

The problem was just with the upper bound. Putting 10 instead of None for the upper bound works. Note however that putting np.inf for the upper bound produce the wrong answer.

J.D.
  • 139
  • 4
  • 14