In working on an estimation problem, I created three Gaussian-like functions. The ML estimate could be seen as the argmax of the product of the three functions. In trying to get the code to run faster, I discovered complementary functions to ArgMax
: NArgMax
, and FindArgMax
. However, I can not get the functions NArgMax
and FindArgMax
to agree with the ArgMax
solution. For reference, I believe that the ArgMax
solution is correct, and the other two are not. Without pasting all of my code, here is a MWE that demonstrates the effect:
test1[x_, y_] := 1/.01^2*Exp[-(x^2 + y^2)/0.01^2]
test2[x_, y_] := 1/.1^2*Exp[-((x - 5)^2 + (y - 3)^2)/0.1^2]
ArgMax[test1[x, y] test2[x, y], {x, y}] // AbsoluteTiming
FindArgMax[
test1[x, y]*test2[x, y], {{x, 2.5}, {y, 1.5}}] // AbsoluteTiming
NArgMax[test1[x, y] test2[x, y], {x, y}] // AbsoluteTiming
The results are
{0.0388864, {0.049505, 0.029703}}
{0.102196, {2.5, 1.5}}
{0.0687933, {1.02414*10^30, 8.98768*10^29}}
However, it is worth noting that FindArgMax
throws the warning: FindArgMax::fmgz: Encountered a gradient that is effectively zero. The result returned may not be a maximum; it may be a minimum or a saddle point. >>
. NArgMax
does not produce any warnings or errors.
I believe this warning may be the reason that neither FindArgMax
nor NArgMax
find the proper solution: FindArgMax
simply considers the initial estimate to be the final solution (as it warns), but I do not know why NArgMax
returns such large values for its solution. However, ArgMax
does correctly identify the maximum.
Any help in resolving this would be much appreciated.
AbsoluteTiming
relevant to the question? $\endgroup$ – Taiki Nov 3 '15 at 3:36AbsoluteTiming
is well documented and I figured it didn't really matter. I can remove it, if you think it really detracts from the question. $\endgroup$ – Michael Witt Nov 3 '15 at 3:38test1[x, y] * test2[x, y]
produces ridiculously small numbers for anyx
andy
. I guess none of the results are correct. $\endgroup$ – Taiki Nov 3 '15 at 3:44ArgMax
is correct. The size of the numeric solution shouldn't matter. If you let the variance oftest1
equal the variance oftest2
, the ML estimate should be the midpoint of the two centroids, which is what it produces in that case; andFindArgMax
also would 'find' that result, although that is its initial estimate. $\endgroup$ – Michael Witt Nov 3 '15 at 3:52