Code Monkey home page Code Monkey logo

Comments (8)

jakob-r avatar jakob-r commented on June 28, 2024

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.

from mlrmbo.

swaheera avatar swaheera commented on June 28, 2024

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

from mlrmbo.

jakob-r avatar jakob-r commented on June 28, 2024

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

from mlrmbo.

swaheera avatar swaheera commented on June 28, 2024

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.

from mlrmbo.

swaheera avatar swaheera commented on June 28, 2024
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

from mlrmbo.

jakob-r avatar jakob-r commented on June 28, 2024

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)

from mlrmbo.

swaheera avatar swaheera commented on June 28, 2024

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

from mlrmbo.

swaheera avatar swaheera commented on June 28, 2024

Hello Dr. Richter,,

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

Thanks

from mlrmbo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.