DEoptim in R returns an error when I use the fnMap parameter

I am trying to use DEoptim with the fnMap parameter, which is specified in the documentation "an additional function that will be run after each collection is created", so I am creating this simple test case.

fnm <- function(x) round(x, 2)
fn <- function (x) x ^ 2

upper <- 100
lower <- -100

DEoptim(fn=fn, lower=lower, upper=upper, fnMap=fnm)

The problem is that when I use the fnMap parameter, it returns an error. The { mapping function did not return an object with a dull length NP x (upper) } for any mapping function.

+4
source share
1 answer

Expected revenue is dim NP x length (top). Yours upperis length1. You can try to set dim NP to 1 with control. For instance...

DEoptim(fn=fn, lower=lower, upper=upper, fnMap=fnm,control=DEoptim.control(NP=1))

...

Warning in DEoptim(fn = fn, lower = lower, upper = upper, fnMap = fnm, control = DEoptim.control(NP = 1)) :
  'NP' < 4; set to default value 10*length(lower)

, NP 10 * length(lower), .

fnm <- function(x) matrix(round(x, 2), nrow=10, ncol=1,byrow=TRUE)

, length 1. , , -

fnm <- function(x, Len) matrix(round(x, 2), nrow=10*Len, ncol=Len,byrow=TRUE)

DEoptim

DEoptim(fn=fn, lower=lower, upper=upper, fnMap=function(x) fnm(x,length(upper)))
+5

Source: https://habr.com/ru/post/1598892/


All Articles