Scipy.optimize.minimize returning incorrect results
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Question
01:32 Accepted answer (Score 6)
02:11 Answer 2 (Score 5)
02:28 Thank you
--
Full question
https://stackoverflow.com/questions/2747...
Accepted answer links:
[scipy.optimize.minimize_scalar]: http://docs.scipy.org/doc/scipy-0.14.0/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #scipy
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Mysterious Puzzle
--
Chapters
00:00 Question
01:32 Accepted answer (Score 6)
02:11 Answer 2 (Score 5)
02:28 Thank you
--
Full question
https://stackoverflow.com/questions/2747...
Accepted answer links:
[scipy.optimize.minimize_scalar]: http://docs.scipy.org/doc/scipy-0.14.0/r...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #scipy
#avk47
ACCEPTED ANSWER
Score 6
If you use the function scipy.optimize.minimize_scalar you get the expected result:
results = minimize_scalar(error_p, tol=0.00001)
print results['x'], results['fun']
>>> 1.88536329298 0.000820148069544
Why does scipy.optimize.minimize not work? My guess is that your function error_p is malformed from a numpy perspective. Try this:
MU = np.linspace(0,20,100)
error_p(MU)
and you'll see that it fails. Your function isn't tailored to take in an array of inputs and spit out an array of outputs, which I think is what minimize is looking for.
ANSWER 2
Score 5
Change
theory = [poisson.pmf(x, mu) for x in x]
to
theory = poisson.pmf(x, mu)
and it works as expected.