Scipy.optimize.minimize returning incorrect results
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Light Drops
--
Chapters
00:00 Scipy.Optimize.Minimize Returning Incorrect Results
00:55 Accepted Answer Score 6
01:28 Answer 2 Score 5
01:39 Thank you
--
Full question
https://stackoverflow.com/questions/2747...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #numpy #scipy
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT
Music by Eric Matyas
https://www.soundimage.org
Track title: Light Drops
--
Chapters
00:00 Scipy.Optimize.Minimize Returning Incorrect Results
00:55 Accepted Answer Score 6
01:28 Answer 2 Score 5
01:39 Thank you
--
Full question
https://stackoverflow.com/questions/2747...
--
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.