I have two codes which carry out the same task, that is finding the maxima of a function. The function I am considering is a log-likelihood function. Since I am modelling a quantum process, I am using a random number generator to generate to measurement outcomes {m1,m1,m2} which then defines the log-likelihood function. The codes follow identical mathematical approaches, but In Code 1 I use the Mathematica built-in function NMaximize[] to find the critical points (which maximize the function) directly from the log-likelihood function, and in Code 2 I first take the derivative of the function and analytically solve for the points which yield the a zero derivative using the built-in Mathematica Solve[] function. I would expect these two approaches to yield identical results (or very similar results) for large iteration counts. But Code 1 does not converge to the expected value of 1.5, but instead maintains a negative bias by converging to about 1.475 (regardless of the number of trials). Code 2 converges to 1.5 as expected. Could anyone advise on the cause of the discrepancy. Many thanks for any assistance.
Note: I have tried setting different Methods in the NMaximum function but still get a negative bias. There also does not seem to be an appreciable difference when considering the built-in Maximum function as opposed to NMaximum, one still gets a negative bias.