I’m getting a MethodError
in LBFGS
when trying to use a custom mutable struct that inherits from FieldVector
for an optimization problem.
using StaticArrays
using Optimization, OptimizationOptimJL
mutable struct Point{T} <: FieldVector{2, T}
x::T
y::T
end
function rosenbrock(v, p)
(p[1] - v[1])^2 + p[2] * (v[2] - v[1]^2)^2
end
v₀ = Point(0., 0.)
p = (1., 100.)
f = OptimizationFunction(rosenbrock, Optimization.AutoForwardDiff())
prob = OptimizationProblem(f, v₀, p)
sol = solve(prob, LBFGS()) # ERROR: MethodError: no method matching Optim.LBFGSState(::Point{…}, ...)
My first attept was to write a new rosenbrock
method as
function rosenbrock(v::Point, p)
rosenbrock(SVector(v.x, v.y), p)
end
but of course this still fails. Is there a good way to get this to work?