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 FindArgMaxto 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.
AbsoluteTimingrelevant to the question? – Taiki Nov 03 '15 at 03:36AbsoluteTimingis well documented and I figured it didn't really matter. I can remove it, if you think it really detracts from the question. – Michael Witt Nov 03 '15 at 03:38test1[x, y] * test2[x, y]produces ridiculously small numbers for anyxandy. I guess none of the results are correct. – Taiki Nov 03 '15 at 03:44ArgMaxis correct. The size of the numeric solution shouldn't matter. If you let the variance oftest1equal the variance oftest2, the ML estimate should be the midpoint of the two centroids, which is what it produces in that case; andFindArgMaxalso would 'find' that result, although that is its initial estimate. – Michael Witt Nov 03 '15 at 03:52test1[x, y] * test2[x, y]is very small, numerical methods byFindArgMaxandNArgMaxwouldn't work. Only an exact method done byArgMaxwould. – Taiki Nov 03 '15 at 04:01test2to produce larger values overall by changing its center to(0.25,0.25), and I still do not get correct answers, e.g.test2[x_, y_] := 1/.1^2*Exp[-((x - .25)^2 + (y - .25)^2)/0.1^2]– Michael Witt Nov 03 '15 at 04:01NArgMax[test1[x, y] * test2[x, y], {x, y}, WorkingPrecision -> 10]for example helps even without using exact numbers. – Taiki Nov 03 '15 at 04:10WorkingPrecisiondoes actually help make bothNArgMaxandFindArgMaxwork, assuming your estimate forFindArgMaxis close enough. This is the first time that changingWorkingPrecisionhas actually helped me resolve a problem. Thanks! – Michael Witt Nov 03 '15 at 04:28WorkingPrecision->2works better than whatever the default is. Why would that be? – Michael Witt Nov 03 '15 at 04:31WorkingPrecision->2producing a good result. (I wouldn't call a wrong result w/o warnings an improvement). Anyway is this a real problem?ArgMaxworks, use it... – george2079 Nov 03 '15 at 17:09