(L-)BFGS for a user-defined function

Hi,
I have a complex nonlinear user-defined function (blackbox) that I am trying to minimize using BFGS or L-BFGS. I found this library, but I can’t use it. I think it works only for simple algebraic expressions, it that correct? and what would be the alternative?

1 Like

NLopt.jl has an L-BFGS implementation, but you will need to supply gradients. Depending on the complexity of your objective, you might be able to derive the gradient via autodiff

4 Likes

No, it works, in principle, on any function. If it is differentiable, as mentioned above, you might want to provide the manually computed gradient or use an automatic differentiation package. If your function is not differentiable, other methods exist that will probably perform better than L-BFGS.

4 Likes

It should work for black box functions.

2 Likes

I get the following error massage when I try to use the library (I also provide a gradient):

MethodError: no method matching optimize(::typeof(AugmantedLagrangiannn), ::typeof(AugmantedLagrangianGradient_tryy), ::BFGS{LineSearches.InitialStatic{Float64},LineSearches.HagerZhang{Float64,Base.RefValue{Bool}},Nothing,Nothing,Flat})
Closest candidates are:
  optimize(::Any, ::Any, ::Any, !Matched::AbstractArray; inplace, autodiff, kwargs...) at C:\Users\u0132800\.juliapro\JuliaPro_v1.4.0-1\packages\Optim\onG5j\src\multivariate\optimize\interface.jl:104
  optimize(::Any, ::Any, ::Any, !Matched::AbstractArray{T,N} where N, !Matched::Optim.Options; inplace, autodiff) where T at C:\Users\u0132800\.juliapro\JuliaPro_v1.4.0-1\packages\Optim\onG5j\src\multivariate\optimize\interface.jl:131
  optimize(::Any, ::Any, ::Any, !Matched::AbstractArray{T,N} where N, !Matched::Optim.AbstractOptimizer) where T at C:\Users\u0132800\.juliapro\JuliaPro_v1.4.0-1\packages\Optim\onG5j\src\multivariate\optimize\interface.jl:160
  ...
top-level scope at untitled-0b01580f0f477249f7f9af02f60c1251:178

where AugmantedLagrangiannn(X) is my function and the gradient is AugmantedLagrangianGradient_tryy(X)

Can you provide a minimum working example (MWE) that reproduces your error? From what you provided above, it looks like you didn’t supply the optimizer with a starting value for X. The Optim.jl documentation has some basic examples to get you started.

3 Likes

I think you have forgotten the initial guess when you call optimize