Search code examples
roptimizationintegernonlinear-optimizationtype-constraints

Fixing few parameters in DEoptim as Integer


In DEoptim how to fix parameters as integers in lower and upper bounds opt <- DEoptim(function,lower = c(0.03,17,5,0.002), upper = c(0.12,30,15,-0.5))

In the below example the 2nd, 3rd parameters should be integers but the optimizer takes it as float with upto 6 decimals.

How to fix them as integers?


Solution

  • Here we need to create a Mapping function to map each parameter type. In the above example we have to create the following function,

    Mapfun <- function(x){

    x[1] <- round(x[1],2) #you can decide to what decimal the optimization to be done by explicit defining the digits here, i need 2 digits

    x[2:3] <- round(x[2:3]) #implies that they are integer

    x[4] <- round(x[4],3) #here i need 3 digits

    }

    Now for using in DeOptim:

    opt <- Deoptim(function,lower = c(0.03,17,5,0.002), upper = c(0.12,30,15,-0.5),fnMap = Mapfun)