Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的NSGA2遗传算法_R_Genetic Algorithm - Fatal编程技术网

R中的NSGA2遗传算法

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",

我正在研究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",
        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)