# unused arguments (forbidden = expression(x2 > x1))

I am working with the R programming language. I am learning how to use the "mlrMBO" library for the purpose of optimizing multi-objective functions (using Bayesian Methods).

In my example, for the following constraints:

`````` x2 >x1 AND x4 >x3
``````

I want to optimize the following (multi-objective) function I defined:

``````bayesian_function <- function(x1, x2, x3, x4) {
var_1 <- sin(x1 + x2)
var_2 <- cos(x1 - x2)
var_3 <- x1 + x4
var_4 <- x3 + x4 -7
goal_1 = sum(var_1 + var_2 + var_3 + var_4)
goal_2 = var_1 + var_2 - var_3 + var_4
goal_3 = var_1 + var_2 - var_3 + 2*var_4

return(c(goal_1, goal_2, goal_3))

}
``````

To do this, I tried the follow the necessary "mlrMBO" syntax to optimize this function for the given constraints and allowed ranges for "x1, x2, x3, x4" :

``````#load libraries
library(mlrMBO)
library(ParamHelpers)
library(smoof)

obj.fn = makeMultiObjectiveFunction(
name = "My test function",
fn = function(x1, x2, x3, x4) {
var_1 <- sin(x1 + x2)
var_2 <- cos(x1 - x2)
var_3 <- x1 + x4
var_4 <- x3 + x4 -7
goal_1 = sum(var_1 + var_2 + var_3 + var_4)
goal_2 = var_1 + var_2 - var_3 + var_4
goal_3 = var_1 + var_2 - var_3 + 2*var_4

return(c(goal_1, goal_2, goal_3))

},
#define acceptable ranges
par.set = makeNumericParamSet(
makeNumericParam("x1", lower = 20, upper = 40),
makeNumericParam("x2", lower = 30, upper = 45),
makeNumericParam("x3", lower = 10, upper = 20),
makeNumericParam("x4", lower = 10, upper = 50),
#define constraints
forbidden = expression(x2 >x1),
forbidden = expression(x4 >x3)
),

minimize=TRUE
)

#create control gird
control=makeMBOControl(propose.points=1, final.method="best.predicted", final.evals=10)
control=setMBOControlTermination(control, iters=10)
control=setMBOControlInfill(control, crit=makeMBOInfillCritEI())

#perform optimization
lrn=makeMBOLearner(control, obj.fun)
``````

The first part of this code returns the following error and preventing me from running the rest of the code:

``````Error in makeNumericParamSet(makeNumericParam("x1", lower = 20, upper = 40),  :
unused arguments (forbidden = expression(x2 > x1), forbidden = expression(x4 > x3))
``````

It seems that there is a problem while defining the constraints (i.e. "forbidden" statement). I tried reading more about this function makeParamSet function - RDocumentation , but I can't seem to figure out what I am doing wrong.

Can someone please show me why this error is being produced?

Thanks

I think you can't declare more than one `forbidden =` in a param set
Perhaps try

``````#define constraints
forbidden = expression(x2 >x1 & x4 >x3)
``````

I tried to put everything together:

``````#load libraries
library(mlrMBO)
library(ParamHelpers)
library(smoof)

obj.fn = makeMultiObjectiveFunction(
name = "My test function",
fn = function(x1, x2, x3, x4) {
var_1 <- sin(x1 + x2)
var_2 <- cos(x1 - x2)
var_3 <- x1 + x4
var_4 <- x3 + x4 -7
goal_1 = sum(var_1 + var_2 + var_3 + var_4)
goal_2 = var_1 + var_2 - var_3 + var_4
goal_3 = var_1 + var_2 - var_3 + 2*var_4

return(c(goal_1, goal_2, goal_3))

},
#define acceptable ranges
par.set = makeParamSet(
makeNumericParam("x1", lower = 20, upper = 40),
makeNumericParam("x2", lower = 30, upper = 45),
makeNumericParam("x3", lower = 10, upper = 20),
makeNumericParam("x4", lower = 10, upper = 50),
#define constraints
forbidden = expression(x2 >x1 & x4 >x3)
),

minimize=TRUE
)

#create control gird
control=makeMBOControl(propose.points=1, final.method="best.predicted", final.evals=10)
control=setMBOControlTermination(control, iters=10)
control=setMBOControlInfill(control, crit=makeMBOInfillCritEI())

#perform optimization
lrn=makeMBOLearner(control, obj.fun)
``````

But now this results in a new error:

`Error in fn(unlist(x), ...) : unused argument (unlist(x))`

Do you know why this error is being produced?

Thank you for all your help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.