jmbejara / comp-econ-sp19

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2019)
48 stars 26 forks source link

Using opt.minimize on discrete data #74

Open jbendelac opened 5 years ago

jbendelac commented 5 years ago

Hello, I'm practicing running mle on discrete functions, and have been having trouble using the opt.minimize function with discrete datasets in the examples I am working with. Can opt.minimize work with discrete data, and if not is there another function I can use instead of opt.minimize?

jmbejara commented 5 years ago

Hi. Good questions. Could you elaborate a little more? If you're asking about "discrete optimization", we didn't cover any of this in class. If you're wondering about using MLE to estimate the parameters of discrete random variables, such estimation falls within the domain of "continuous optimization." Our usual estimation procedures should work for this. Though, there are a lot of times when an optimizer will fail for one reason or another. If you're trying to optimize a function of one variable, sometimes using scipy.optimize.minimize_scalar works better.

jbendelac commented 5 years ago

I'm wondering about using MLE to estimate parameters of discrete random variables. My probability mass function and neg log lik functions work correctly, but my opt.minimize is returning the initial guess, no matter what the initial guess is. How would I go about fixing this problem?

jmbejara commented 5 years ago

Ok. Have you tried scipy.optimize.minimize_scalar? Also, have you tried other optimization methods within minimize? Take a look at the method keyword argument: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html

But try minimize_scalar first.