2
由於某些原因,當我使用parallel = TRUE選項時,GA算法返回「非二進制運算符的非數值參數」。 優化算法似乎沒有這個選項,或者當設置parallel = FALSE時工作。 我已經安裝了所有需要的軟件包,它們都是最新的。我在64位機器上使用的R版本是3.3.2。GA算法在並行計算時返回「二進制運算符的非數值參數」
我基本上調用函數內的函數,我嘗試優化。下面的代碼是返回相同錯誤代碼的問題的一般結構的一個非常簡單的例子。
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
)
謝謝你的幫助。