Julia:最小化具有多个参数的函数(BFGS) [英] Julia: Minimise a function with multiple arguments (BFGS)
问题描述
我正在尝试使用 Optim.jl 库使用 BFGS 算法最小化具有多个参数的函数.
I am trying to minimise a function with multiple arguments with the Optim.jl library, using a BFGS algorithm.
在 Optim 库的 GitHub 网站上,我找到了以下工作示例:
In the GitHub website of the Optim library, I found the following working example:
using Optim
rosenbrock(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
result = optimize(rosenbrock, zeros(2), BFGS())
假设我的目标函数是:
fmin(x, a) = (1.0 - x[1])^a + 100.0 * (x[2] - x[1]^2)^(1-a)
如何使用 optimize 传递附加的常量参数 a?
How can I pass the additional - constant - argument a using optimize?
推荐答案
最简单的方法是传递一个变量的匿名函数,该函数使用参数集调用您的原始函数.例如,使用 fmin 的变体:
The simplest way is to pass an anonymous function of one variable which calls your original function with the parameters set. For example, using a variant of your fmin:
julia> fmin(x, a) = (1.0 - x[1])^a + 100.0 * (x[2] - x[1]^2)^(a)
fmin (generic function with 1 method)
julia> r = optimize(x->fmin(x, 2), zeros(2), BFGS());
julia> r.minimizer, r.minimum
([1.0,1.0],5.471432684244042e-17)
或者,您可以为一个变量创建一个单独的命名函数,该函数关闭您喜欢的任何参数.Python 中的 scipy.optimize.minimize
中的 args
没有等价物,您可以将不变的参数作为元组单独传递,AFAIK.
Alternatively you can make a separate named function of one variable which closes over whatever parameters you like. There's no equivalent to the args
in scipy.optimize.minimize
in Python where you pass the non-varying arguments separately as a tuple, AFAIK.
这篇关于Julia:最小化具有多个参数的函数(BFGS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!