1
$\begingroup$

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."

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

1 Answer 1

5
$\begingroup$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.