Optimize a function

[1]:
# import libraries
import jax.numpy as jnp
from optymus import Optimizer
from optymus.benchmark import Mccormick

[2]:
# define the objective function
f = Mccormick()

# define initial guess
initial_point = jnp.array([-3.0, 2.0])
[3]:
# instantiate the optimizer with the objective function and the initial point
# select the method to be used
opt = Optimizer(
    f_obj=f,
    x0=initial_point,
    method='bfgs',
)
BFGS 0:   4%|▍         | 4/100 [00:00<00:20,  4.64it/s]
[4]:
# print a short report about the optimization process
opt.report()
[4]:
bfgs
Initial guess: [-3. 2.]
Optimal solution: [-0.54719756 -1.54719756]
Objective function value: -1.9132229549810367
Number of iterations: 4
Time elapsed: 0.948
[7]:
# plot the results
opt.plot(lb=-5, ub=5, n_levels=500)