R中的NSGA2遗传算法
我正在研究R(库mco)上的NSGA2包 我的NSGA2代码需要永远运行,所以我想知道: 1)有没有办法限制解数值的精度(比如,可能高达小数点后3位),而不是无限大? 2)如何设置相等约束(在线约束似乎都是>=或R中的NSGA2遗传算法,r,genetic-algorithm,R,Genetic Algorithm,我正在研究R(库mco)上的NSGA2包 我的NSGA2代码需要永远运行,所以我想知道: 1)有没有办法限制解数值的精度(比如,可能高达小数点后3位),而不是无限大? 2)如何设置相等约束(在线约束似乎都是>=或 VTR = get.hist.quote(instrument = 'VTR', start="2010-01-01", end = "2015-12-31", quote = c("AdjClose"),provider = "yahoo",
VTR = get.hist.quote(instrument = 'VTR',
start="2010-01-01", end = "2015-12-31",
quote = c("AdjClose"),provider = "yahoo",
compress = "d")
ObjFun1 <- function (xh){
f1 <- sum(HSVaR_P(merge(VTR, CMI, SPLS, KSS, DVN, MAT, LOE, KEL, COH, AXP), xh, 0.05, 2))
tempt = merge(VTR, CMI, SPLS, KSS, DVN, MAT, LOE, KEL, COH, AXP)
tempt2 = tempt[(nrow(tempt)-(2*N)):nrow(tempt),]
for (i in 1:nrow(tempt2))
{
for (j in 1:ncol(tempt2))
{
if (is.na(tempt2[i,j]))
{
tempt2[i,j] = 0
}
}
}
f2 <- ((-1)*abs(sum((xh*t(tempt2)))))
c(f1=f1,f2=f2)
}
Constr <- function(xh){
totwt <- (1-sum(-xh))
totwt2 <- (sum(xh)-1)
c(totwt,totwt2)
}
Solution1 <- nsga2(ObjFun1, n.projects, 2,
lower.bounds=rep(0,n.projects), upper.bounds=rep(1,n.projects),
popsize=n.solutions, constraints = Constr, cdim=1,
generations=generations)