# How to do BayesianMinimization in 2D?

Studying a new experimental BayesianMinimization command in 14.0 and following an example from the documentation

bo = BayesianMinimization[(# - 2)^2 + 1 &, Interval[{0, 4}]]


, I try

BayesianMinimization[Sin[#1] + Cos[#2] &, {Interval[{-3, 3}], Interval[{-3, 3}]}]


and

BayesianMinimization[Sin[#1] + Cos[#2] &, Rectangle[{-3, 3}, {-3, 3}]]


with the same result

BayesianMinimization::bdconfgenerator: The configurations are not valid.

That place in the documentation

Configurations can be of any form accepted by Predict (single data element, list of data elements, association of data elements, etc.) and of any type accepted by Predict (numerical, textual, sounds, images, etc.).

is not clear to me. So is it possible to do Bayesian optimization with Mathematica in two dimensions?

Addition. I'd like to add that f[x_?NumericQ, y_?NumericQ] := Sin[x] + Cos[y]; reg = Rectangle[{-3, -3}, {3, 3}]; BayesianMinimization[f, reg] up to another example from the documentation performs an error "BayesianMinimization::bdfnconfig: The function should be real valued."

• BayesianMinimization[Sin[#[[1]]] + Cos[#[[2]]] &, RandomReal[{-3, 3}, 2] &] seems to work, but I'm not sure why it's so fussy. Feb 8 at 11:01
• @SjoerdSmit: Thank you, it does work. However, how about more complicated regions in 2D? Feb 8 at 11:11
• Use Rectangle[{-3, -3}, {3, 3}].
– Syed
Feb 8 at 11:37
• @Syed: I mean something like ImplicitRegion[y<=Sin[x]+x&&y>=x^2-4,{x,y}]. Feb 8 at 11:48
• @user64494 Maye something like BayesianMinimization[Sin[#[[1]]] + Cos[#[[2]]] &, RandomPoint[Rectangle[{-3, -3}, {3, 3}]] & ]. But with a more complicated region than that. Feb 8 at 11:55

The following works:

BayesianMinimization[Sin[#[[1]]] + Cos[#[[2]]] &, Rectangle[{-3, -3}, {3, 3}]]


or

BayesianMinimization[Sin[#[[1]]] + Cos[#[[2]]] &, RandomPoint[Rectangle[{-3, -3}, {3, 3}]]&]


If you want to use more complicated regions, it's recommended to use DiscretizeRegion to create something that can be sampled quickly by RandomPoint.

• +1. Many thanks from me to you. I'll be waiting for other answers some time . Feb 8 at 13:07
• Even BayesianMinimization[Sin[#[[1]]] + Cos[#[[2]]] &, ImplicitRegion[y <= Sin[x] + x && y >= x^2 - 4, {x, y}]] works. Feb 8 at 18:56