我尝试从Optim.jl
documentation运行一个示例:
using Optim
f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
function g!(G, x)
G[1] = -2.0 * (1.0 - x[1]) - 400.0 * (x[2] - x[1]^2) * x[1]
G[2] = 200.0 * (x[2] - x[1]^2)
end
lower = [1.25, -2.1]
upper = [Inf, Inf]
initial_x = [2.0, 2.0]
inner_optimizer = GradientDescent()
results = optimize(f, g!, lower, upper, initial_x, Fminbox(inner_optimizer))
它返回:
ERROR: LoadError: MethodError: Cannot `convert` an object of type Optim.GradientDescent{LineSearches.InitialPreviou
s{Float64},LineSearches.HagerZhang{Float64},Void,Optim.##43#45} to an object of type Optim.Fminbox
This may have arisen from a call to the constructor Optim.Fminbox(...),
since type constructors fall back to convert methods.
我不知道出什么问题了。如果问题不使用上下限,它可以运行:
results = optimize(f, g!, initial_x)
答案 0 :(得分:3)
您最有可能使用Optim版本0.14.1,在这种情况下,您应该编写:
optimize(f, g!, initial_x, lower, upper, Fminbox{GradientDescent}())
一切顺利进行。
与您的代码的区别是:
Fminbox
构造函数您使用的语法要求Optim 0.15.1可以正常工作。