I am attempting to perform a numerical optimisation of a "black box" function in Mathematica. Schematically it goes like this:
NMinimize[{comb[x,y,z], x > 0}, {x,y,z}]
where comb[x,y,z] is defined similarly to this:
comb[x_,y_,z_] := Module[{},
Print[x,y,z];
M = FindMaximum[SkewNormal[a,x,y,z], {a,x}] // First;
val = f[x,y,z,M];
Return[val];
];
However, all of the minimisation functions I have tried seem to not immediately provide comb[x,y,z] with numerical values, and it ends up trying to evaluate the FindMaximum with symbolic values for x,y,z (which is easily verified because the Print[x,y,z] also evaluates symbolically). The Findmaximum thus fails (FindMaximum::nrnum: The function value blah blah is not a real number) and so the minimisation fails.
How do I fix up the evaluation order so that the sub-functions of comb are evaluated with numerical values?
Evaluation order for
FindMinimum
,FindMaximum
,FindRoot
andFindFit
is documented on the tutorial/UnconstrainedOptimizationSymbolicEvaluation Documentation page. I think that something very similar is applicable to theNMinimize
function. The description is quite lengthy so I will cite here only the proposed solution from that page:How about changing
comb
towhich causes the definition of
comb
to be evaluated only if its arguments are numbers?