R 遗传算法返回";二进制运算符的非数值参数;当并行计算
出于某种原因,当我使用parallel=TRUE选项时,GA算法返回“非数值参数到二进制运算符”。 如果没有该选项或设置parallel=FALSE,优化算法似乎可以工作。 我已经安装了所有必要的软件包,它们都是最新的。我使用的R版本是64位机器上的3.3.2 我基本上是在我试图优化的函数中调用一个函数。下面的代码是返回相同错误代码的问题的一般结构的一个非常简单的示例R 遗传算法返回";二进制运算符的非数值参数;当并行计算,r,parallel-processing,genetic-algorithm,R,Parallel Processing,Genetic Algorithm,出于某种原因,当我使用parallel=TRUE选项时,GA算法返回“非数值参数到二进制运算符”。 如果没有该选项或设置parallel=FALSE,优化算法似乎可以工作。 我已经安装了所有必要的软件包,它们都是最新的。我使用的R版本是64位机器上的3.3.2 我基本上是在我试图优化的函数中调用一个函数。下面的代码是返回相同错误代码的问题的一般结构的一个非常简单的示例 fun_in <- function(a, b, c, d, e) { return(a + b + c + d +
fun_in <- function(a, b, c, d, e)
{
return(a + b + c + d + e)
}
fun_out <- function(a, b, c, d, e, f, g)
{
x <- f +g
y <- fun_in(a = a, b = b, c = c, d = d, e = e)
z <- x + y
return(z)
}
library('GA')
a <- 1
b <- 1
c <- 1
d <- 1
e <- 1
f <- 1
g <- 1
fitness <- function(x) -fun_out(a, b, c, d, e, f, g)
lower_bound <- c(1,1,1,1,1,1,1)
upper_bound <- c(5,5,5,5,5,5,5)
coef_names <- c('a', 'b', 'b', 'd', 'e', 'f', 'g')
GA <- ga(type = "real-valued",
fitness = fitness,
min = lower_bound,
max = upper_bound,
popSize = 100,
maxiter = 1000,
pmutation = 0.8,
pcrossover = 0.8,
maxFitness = 1e-5,
names = coef_names,
parallel = TRUE
)
fitness()中参数名的简单修复
——健康
--- fitness <- function(x) -fun_out(a, b, c, d, e, f, g)
+++ fitness <- function(x) -fun_out(x[1], x[2], x[3], x[4], x[5], x[6], x[7])