Closed malmaud closed 8 years ago
This is super weird. I'm looking into it -- there are various combinations of observations that do or don't work...
observed=np.array([0, 1]) #error
observed=np.array([0, 1, 1]) #fine!
observed=np.array([0, 0, 1, 1]) #fine!
observed=np.array([0, 0, 0, 1, 1]) #error
at the very least, the output should be consistent.
So this is fun: fmin_powell
sets a bracket to start optimizing in a fairly inscrutable manner, searching through floats, but theano is casting everything to int32
, and using them as indexes in emissions
. For whatever reason, if you initialize at 1
, fmin_powell
first evaluates logp
at -1.618034
, which rounds to -1, which pymc3 handles as 1e+100. Initializing at 0 has fmin_powell
start at 2.6180339999999998
, which rounds to 2, which throws an IndexError
.
Trying to figure out the right place to handle this, since we probably should error immediately, or do specific handling for categorical variables -- @fonnesbeck?
I would not have expected Powell's method to work with a binary variable. For a problem like this, I think brute force is the way forward (scipy.optimize.brute
). It will required a tweak to find_MAP
, which I can add.
Using the PR above, running:
map_state = pm.find_MAP(vars=[state], fmin=pm.starting.optimize.brute, ranges=[slice(0,2)])
will work. Since there are only two states, brute force is just fine. Would have been nice to automatically find the range of the variable, but I could not think of a good way to do this.
Wow, that's a bizarre bug. I'll keep an eye out for any weird behaviour like that.
I think specific handling for categorical variables would be a good idea.
On Sun, Oct 23, 2016 at 4:15 PM, Colin notifications@github.com wrote:
So this is fun: fmin_powellsets a bracket to start optimizing in a fairly inscrutable manner, searching through floats, but theano is casting everything to int32, and using them as indexes in emissions. For whatever reason, if you initialize at 1, fmin_powell first evaluates logp at -1.618034, which rounds to -1, which pymc3 handles as 1e+100. Initializing at 0 has fmin_powell start at 2.6180339999999998, which rounds to 2, which throws an IndexError.
Trying to figure out the right place to handle this, since we probably should error immediately, or do specific handling for categorical variables -- @fonnesbeck https://github.com/fonnesbeck?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pymc-devs/pymc3/issues/1469#issuecomment-255594170, or mute the thread https://github.com/notifications/unsubscribe-auth/AA8DiAhkWun10wfXwrUeIAr3kwjTe_R1ks5q23oQgaJpZM4KcVPl .
Peadar Coyle Skype: springcoilarch www.twitter.com/springcoil peadarcoyle.wordpress.com
This code generates an error:
But the code runs fine when the observed value is changed:
The error is
Thanks for your help!