';nloptr';包装在';R';产生不同的结果?
定义数据';nloptr';包装在';R';产生不同的结果?,r,algorithm,optimization,R,Algorithm,Optimization,定义数据 N_h <- c(39552, 38347, 43969, 36942, 41760) s_1 <- c(4.6, 3.4, 3.3, 2.8, 3.7) s_2 <- c(11.7, 9.8, 7.0, 6.5, 9.8) s_3 <- c(332, 357, 246, 173, 279) s_cap <- c(0.5, 0.5, 0.5, 0.5, 0.5) s_h1 <- s_1+s_cap s_
N_h <- c(39552, 38347, 43969, 36942, 41760)
s_1 <- c(4.6, 3.4, 3.3, 2.8, 3.7)
s_2 <- c(11.7, 9.8, 7.0, 6.5, 9.8)
s_3 <- c(332, 357, 246, 173, 279)
s_cap <- c(0.5, 0.5, 0.5, 0.5, 0.5)
s_h1 <- s_1+s_cap
s_h2 <- s_2+s_cap
s_h3 <- s_3+s_cap
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cost <- c(3,4,5,6,7)
c_cap <- c(1.5, 1.5, 1.5, 1.5, 1.5)
c<- cost
c
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N <- sum(N_h)
d_h <- c(N_h/N)
d1 <-(d_h)^2*s_h1
d2 <-(d_h)^2*s_h2
d3 <-(d_h)^2*s_h3
v<- c(0.0037, 0.00868, 0.25)
i<-1; j<-2; k<-3
Gamma<-5
客观的
f2<-function(x, d1, d2, d3, c, Gamma){
return(x[1])
}
用不同代码的同一算法求解
Robust1 <- cobyla(x0, f2, hin = g2,lower = lowerb, upper = upperb,
nl.info = TRUE,control = list(xtol_rel = 1e-8, maxeval = 100000))
然而,这两种代码使用相同的算法,但产生不同的结果。有人能解释一下区别吗?
非常感谢。可以看出,当直接使用COBYLA算法时,它根本不收敛,它提供了一些当前值而不是最佳值
*Current value of objective function: -19989642.9275736
Current value of controls: -19989643 220.9959 214.9653 215.0129 215.0129 215.0129 2 2 2 2 2 2*
然而,使用“nloptr”包,该算法成功收敛并提供最佳结果
Optimal value of objective function: 6742.76053944518
Optimal value of controls: 6742.761 234.7352 235.9822 224.6824 158.3741 227.2298 290.1293 70.93367 63.84037 51.29771 30.13394 53.6419
因此,“nloptr”包提供了所需的结果
Robust <- nloptr(x0=x0,
eval_f = f2,
lb=lowerb,
ub=upperb,
eval_g_ineq=g2,
opts=list("algorithm"="NLOPT_LN_COBYLA",
maxeval=100000,
"xtol_rel"=1.0e-8,
"print_level" = 0))
Call:
nloptr(x0 = x0, eval_f = f2, lb = lowerb, ub = upperb, eval_g_ineq = g2,
opts = list(algorithm = "NLOPT_LN_COBYLA", maxeval = 1e+05, xtol_rel = 1e-08, print_level = 0))
Minimization using NLopt version 2.4.2
NLopt solver status: 4 ( NLOPT_XTOL_REACHED: Optimization stopped because xtol_rel or xtol_abs (above) was reached. )
Number of Iterations....: 1219
Termination conditions: maxeval: 1e+05 xtol_rel: 1e-08
Number of inequality constraints: 10
Number of equality constraints: 0
Optimal value of objective function: 6742.76053944518
Optimal value of controls: 6742.761 234.7352 235.9822 224.6824 158.3741 227.2298 290.1293 70.93367 63.84037 51.29771 30.13394 53.6419
Robust1 <- cobyla(x0, f2, hin = g2,lower = lowerb, upper = upperb,
nl.info = TRUE,control = list(xtol_rel = 1e-8, maxeval = 100000))
Call:
nloptr(x0 = x0, eval_f = fn, lb = lower, ub = upper, eval_g_ineq = hin, opts = opts)
Minimization using NLopt version 2.4.2
NLopt solver status: 5 ( NLOPT_MAXEVAL_REACHED: Optimization stopped because maxeval (above) was reached. )
Number of Iterations....: 100000
Termination conditions: stopval: -Inf xtol_rel: 1e-08 maxeval: 1e+05 ftol_rel: 0 ftol_abs: 0
Number of inequality constraints: 10
Number of equality constraints: 0
Current value of objective function: -19989642.9275736
Current value of controls: -19989643 220.9959 214.9653 215.0129 215.0129 215.0129 2 2 2 2 2 2
*Current value of objective function: -19989642.9275736
Current value of controls: -19989643 220.9959 214.9653 215.0129 215.0129 215.0129 2 2 2 2 2 2*
Optimal value of objective function: 6742.76053944518
Optimal value of controls: 6742.761 234.7352 235.9822 224.6824 158.3741 227.2298 290.1293 70.93367 63.84037 51.29771 30.13394 53.6419