Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Error in as.data.frame.OptPathDF(opt.path, include.rest = FALSE) : No elements where selected (via 'dob' and 'eol')! #516

Open
swaheera opened this issue Jul 15, 2021 · 8 comments

Comments

@swaheera
Copy link

I recently got this error while trying to perform multiobjective constrained optimization with the mlrMBO library:


library(mlrMBO)

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))
        
    },
    n.objectives = 3L,
    #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 | x3 > x4)
    ),
    
    minimize=rep(TRUE,3)
)

#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)

res = mbo(obj.fun, design = NULL, learner = lrn, control = ctrl, show.info = TRUE)

#error
Warning in generateDesign(n.params * 4L, par.set, fun = lhs::maximinLHS) :
  generateDesign could only produce 0 points instead of 16!
Computing y column(s) for design. Not provided.

Error in as.data.frame.OptPathDF(opt.path, include.rest = FALSE) : 
  No elements where selected (via 'dob' and 'eol')!

I am a bit confused. Where exactly do I need to specify "dob" and "eol"?

Thanks

@jakob-r
Copy link
Member

jakob-r commented Jul 16, 2021

Just by looking at the constraints it looks like they are too narrow (and partly don't make sense)
Forbidden: x2 >x1 | x3 > x4
In other words: x2 should always be smaller or equal then x1 AND x3 always has to be smaller then x4.
Having this in mind it does not make sense to have a higher lower bound for x2 then for x1.
Probably there is no feasible point found in the initial design.

@swaheera
Copy link
Author

I tried removing the constraints all together, but now I get a different error:


library(mlrMBO)

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))
        
    },
    n.objectives = 3L,
    #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)
       
    ),
    
    minimize=rep(TRUE,3)
)

#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)

res = mbo(obj.fun, design = NULL, learner = lrn, control = ctrl, show.info = TRUE)

Error:

Error in checkClass(x, classes, ordered, null.ok) : 
  object 'obj.fun' not found

Is there any way to fix this?
Thanks

@jakob-r
Copy link
Member

jakob-r commented Jul 19, 2021

You named your function obj.fn and not obj.fun

@swaheera
Copy link
Author

Thank you for the correction - I found another typo : "ctrl" vs "control". I fixed both of these errors but now I have a new error.

@swaheera
Copy link
Author

library(mlrMBO)

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))
        
    },
    n.objectives = 3L,
    #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 | x3 > x4)
    ),
    
    minimize=rep(TRUE,3)
)

#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.fn)

res = mbo(obj.fn, design = NULL, learner = lrn, control = control, show.info = TRUE)

I got the following error:

Warning in generateDesign(n.params * 4L, par.set, fun = lhs::maximinLHS) :
  generateDesign could only produce 15 points instead of 16!
Error in checkStuff(fun, design, learner, control) : 
  Objective function has 3 objectives, but the control object assumes 1.

I tried to fix this by changing the number of objectives:

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

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

res = mbo(obj.fn, design = NULL, learner = lrn, control = control, show.info = TRUE)

But then I got a new error:

Error in checkStuff(fun, design, learner, control) : 
  Setting of final.method and final.evals for multi-objective optimization not supported at the moment.

Do you have any idea why this error is being produced?

Thank you so much for your help!

Thanks

@jakob-r
Copy link
Member

jakob-r commented Jul 20, 2021

In MOO there is no final best but only a set of points that are pareto optimal.

You have to change makeMBOControl

control=makeMBOControl(propose.points=1)

@swaheera
Copy link
Author

Hello Dr. Richter,

Thank you for your reply.

I removed the "best.predicted" statement, but the code is still not working:

library(mlrMBO)

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))
        
    },
    n.objectives = 3L,
    #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 | x3 > x4)
    ),
    
    minimize=rep(TRUE,3)
)

#create control gird
control=makeMBOControl(propose.points=1,  n.objectives = 3L, final.evals=10)

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

res = mbo(obj.fn, design = NULL, learner = lrn, control = control, show.info = TRUE)

But this produces the following error

Error in checkStuff(fun, design, learner, control) : 
  Setting of final.method and final.evals for multi-objective optimization not supported at the moment.

As a result of this error, I tried to remove "final.evals":


#create control gird
control=makeMBOControl(propose.points=1,  n.objectives = 3L)

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

res = mbo(obj.fn, design = NULL, learner = lrn, control = control, show.info = TRUE)

But now I get a different error (even though I have specified there are 3 objectives):

Warning in generateDesign(n.params * 4L, par.set, fun = lhs::maximinLHS) :
  generateDesign could only produce 15 points instead of 16!
Error in checkStuff(fun, design, learner, control) : 
  Objective function has 3 objectives, but the control object assumes 1.

If you have time, can you please try running this code on your computer and see if you can get it to work? I have been trying to get this to work for a while, but without any results.

Your Help Is Greatly Appreciated,
Thanks

@swaheera
Copy link
Author

Hello Dr. Richter,,

Can you please take a look at this if you have some time?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants