Uses a jitted version of the maximization routine from SciPy’s fminbound. The algorithm is identical except that it’s been switched to maximization rather than minimization, and the tests for convergence have been stripped out to allow for jit compilation.
Note that the input function func must be jitted or the call will fail.
- func : jitted function
- a : scalar
Lower bound for search
- b : scalar
Upper bound for search
- args : tuple, optional
Extra arguments passed to the objective function.
- maxiter : int, optional
Maximum number of iterations to perform.
- xtol : float, optional
Absolute error in solution xopt acceptable for convergence.
- xf : float
- fval : float
The maximum value attained
- info : tuple
A tuple of the form (status_flag, num_iter). Here status_flag indicates whether or not the maximum number of function calls was attained. A value of 0 implies that the maximum was not hit. The value num_iter is the number of function calls.
>>> @njit ... def f(x): ... return -(x + 2.0)**2 + 1.0 ... >>> xf, fval, info = brent_max(f, -2, 2)