library(ggplot2)
# Simple 2D contour plot with activated heatmap for the Himmelblau function
fn = makeHimmelblauFunction()
print(autoplot(fn))
print(autoplot(fn, render.levels = TRUE, render.contours = FALSE))
print(autoplot(fn, show.optimum = TRUE))
# Now we create 4D function with a mixed decision space (two numeric, one discrete,
# and one logical parameter)
fn.mixed = makeSingleObjectiveFunction(
name = "4d SOO function",
fn = function(x) {
if (x$disc1 == "a") {
(x$x1^2 + x$x2^2) + 10 * as.numeric(x$logic)
} else {
x$x1 + x$x2 - 10 * as.numeric(x$logic)
}
},
has.simple.signature = FALSE,
par.set = makeParamSet(
makeNumericParam("x1", lower = -5, upper = 5),
makeNumericParam("x2", lower = -3, upper = 3),
makeDiscreteParam("disc1", values = c("a", "b")),
makeLogicalParam("logic")
)
)
pl = autoplot(fn.mixed)
print(pl)
# Since autoplot returns a ggplot object we can modify it, e.g., add a title
# or hide the legend
pl + ggtitle("My fancy function") + theme(legend.position = "none")
Run the code above in your browser using DataLab