I am having trouble with a numerical exercise. Here's a simplified version of my problem.
I define two functions to find the solution to two constrained maximization problems:
g[a_,b_,x_]:=NArgMax[{h2[a,b,x,y], CONSTRAINT[a,b,x,y]},{y}][[1]]
f[a_,b_,y_]:=NArgMax[{h1[a,b,x,y], CONSTRAINT[a,b,x,y]},{x}][[1]]
In the above definitions h1(.) and h2(.) are "well-behaved" objective functions, "a" and "b" are parameters and CONSTRAINT[a,b,x,y]
is a given inequality involving the parameters and choice variables.
With these functions, I would like to find a fixed point, say, xstar
:
FindRoot[{xstar==f[a, b, g[a,b,xstar] ]}, {xstar, 0}]
When I try to run FindRoot
with actual numbers for "a" and "b" I get an error saying that the constraint in the maximization problem is not valid. I think the problem is that it attempts to make a symbolic evaluation. I hence tried defining the functions as g[a_,b_,x_?NumberQ]
and f[a_,b_,x_?NumberQ]
, but it didn't work.
However, when I defined:
G[x_?NumberQ]:=g[a,b,x]
F[y_?NumberQ]:=f[a,b,y]
and then fixed values for the parameters by setting them equal to a given number (e.g. a=b=0.1
),then it did work.
It seems then that I am doing something wrong when I use ?NumberQ
in the original function to avoid symbolic evaluation... Any ideas on why it is wrong and how to solve it?
I would like to make a plot for different values of "a" and "b", so running the simulations one by one (as in the solution I mention above that works, by redefining the function only in terms of one variable) is extremely inefficient... and I'm sure there's a smarter way of doing it ! ;)
Here is a complete example using the above notation:
h1[a_, b_, x_, y_] := PDF[BinormalDistribution[{a, b}, {1, 1}, .5], {x, y}]
h2[a_, b_, x_, y_] := PDF[BinormalDistribution[{a, b}, {.5, .5}, .7], {x, y}]
CONSTRAINT[a_, b_, x_, y_] := CDF[BinormalDistribution[{a, b}, {1, 1}, .5], {x, y}]
g[a_, b_, x_] := NArgMax[{h2[a, b, x, y], CONSTRAINT[a, b, x, y] < .5}, {y}][[1]]
f[a_, b_, y_] := NArgMax[{h1[a, b, x, y], CONSTRAINT[a, b, x, y] < .5}, {x}][[1]]
FindRoot[{xstar == f[1, 1, g[1, 1, xstar]]}, {xstar, 0}]
NumberQ
withNumericQ
? $\endgroup$CONSTRAINT
because functions likeNArgMax
,FindMinimum
, ... really like to have explicit (in)equalities there. Can yourCONSTRAINS
be evaluated without numerical values? ThenNArgMax[Evaluate@{h2[a,b,x,y], CONSTRAINT[a,b,x,y]},{y}]
might help. $\endgroup$