Pardon my ignorance (if you’ve seen any recent posts of mine you’ll know I’ve been studying calculus lately) but I’m trying to understand how to find local maxima of a multivariate function with Optim.jl. Given the following function, it’s pretty easy to pick a starting point and let Optim work its magic to find local minima:
using Optim using Plots using Plots.PlotMeasures pyplot(size=(1200,600)) f(x,y) = -5*x*y*exp(-x^2-y^2) res = optimize(x -> f(x,x), [1.0,1.0]) res2 = optimize(x -> f(x,x), [-0.75,-0.75]) # Contour plot with local minima added p = contour( x, y, z, color=:blues, legend=false, xlabel="x", ylabel="y" ) plot!([Optim.minimizer(res)], [Optim.minimizer(res)], marker=:circle) plot!([Optim.minimizer(res2)], [Optim.minimizer(res2)], marker=:circle)
In this case, I can obviously just use the same values from
res2 by switching the sign for the
y value (
-(Optim.minimizer(res)) but is there a way to have it find local maxima just like it does for local minima? The docs seem to only discuss minimizing functions.