我正在尝试使用'nloptr'的'mlsl'函数来最小化非线性函数的输入向量。我不断收到错误消息“ NLOPT_FAILURE:通用故障代码。”
我尝试调整初始条件,下限和上限,xtol_rel,ftol_rel和ftol_abs。我也尝试过提供渐变。错误消息始终是相同的。
# Objective function
Gneg <- function(u) {
with (as.list(params1), {
u1r <- u[1]; u1l <- u[2]; u1s <- u[3]
u2r <- u[4]; u2l <- u[5]; u2s <- u[6]
-1*(((((Wn*a1r*u1r)/((Wn*a1r*u1r)+(Wn*a2r*u2r)))*(N*(1-exp(-((Wn*a1r*u1r)+(Wn*a2r*u2r))))) - (c1rn*u1r + c1ln*u1l + c1sn*u1s))^alpha1)*((((((a1l*u1l)^zl1)*(u1s^zs1))/(((a1l*u1l)^zl1)*(u1s^zs1) + ((a2l*u2l)^zl2)*(u2s^zs2)))*(Wc*C*(1-exp(-((a1l*u1l)+(a2l*u2l))))) - (c1rc*u1r + c1lc*u1l + c1sc*u1s))^beta1))
})}
# initial conditions
x0 <- rep(1, 6)
# lower and upper bounds. Vector u should have only positive elements (because they represent biomass of plant tissues)
lb <- rep(0, 6)
ub <- rep(10000, 6)
# Fixed parameters for function Gneg
params1 <- c(N = 535, Wn = 0.8, Wc = 0.8, a1r=1, a1l=1, a2r=1, a2l=1, c1rn=0.03, c2rn=0.03, c1ln=0.25, c2ln=0.25, c1sn=0.03, c2sn=0.03, c1rc=1.1, c2rc=1.1, c1lc=1.3, c2lc=1.3, c1sc=1.1, c2sc=1.1, C=1000, alpha1=0.99, beta1=0.01, alpha2=0.99, beta2=0.01, zl1 = 1.1, zl2 = 1.1, zs1=1.5, zs2=1.5)
# MLSL/nloptr
solution = mlsl(x0 = x0, fn = Gneg, lower = lb, upper = ub, local.method = "LBFGS", low.discrepancy = TRUE, control = list(xtol_rel = 1e-8, maxeval = 10000))
print(solution)`
我希望得到u的最小值的向量,但是我一直得到的输出是我为初始条件输入的任何内容。输出如下:
$par
[1] 1 1 1 1 1 1
$value
[1] -214.195
$iter
[1] 6
$convergence
[1] -1
$message
[1] "NLOPT_FAILURE: Generic failure code."