Problem:. Numerical optimization on learned PredictorFunction do not seem to behave the same for constraint and region specifications, and the latter fail to evaluate.
Consider the following example:
(* define a noisy function *)
f[x_] := Sin[x] + RandomReal[NormalDistribution[0, 0.1]]
data = (# -> f[#]) & /@ RandomReal[{-Pi, Pi}, 10];
model = Predict[data, Method -> "GaussianProcess"];
If we attempt to find the maximum of the learned function by specifying constraints, we get some warnings about incompatible variable types, but ultimately get an answer:
NMaximize[{model[x], -Pi <= x <= Pi}, x]
No problem! We know how to fix this by making a wrapper that forces the input to be numeric, and all of our warnings disappear:
m[x_?NumericQ] := model[x]
NMaximize[{m[x], -Pi <= x <= Pi}, x]
(* {1.04459, {x -> 1.25916}} *)
But trying to solve the same problem with a region specification fails. Being careful to use the proper syntax for intervals, one attempts:
NMaximize[model[x], {x} \[Element] Interval[{-Pi, Pi}]]
Only a warning and no results output. Furthermore, attempting to use our numericized function, m fails to evaluate:
NMaximize[m[x], {x} \[Element] Interval[{-Pi, Pi}]]
(* NMaximize[m[x], {x} \[Element] Interval[{-\[Pi], \[Pi]}]] *)
(From a practical standpoint, one can obtain the answer using the constraint specification approach demonstrated above, but I would like to understand better the reason why the domain specification fails and how to fix it.)


NMaximizedoesn't evaluate with a region specified byIntervalhere, but if you useNMaximize[ m[x], {x} ∈ ImplicitRegion[-π <= x <= π, {x}]]like bbgodfrey did in your linked question it does evaluate $\endgroup$ImplicitRegionto specify takes 5x longer (according toAbsoluteTiming) than specifying the constraint in the first argument. $\endgroup$