pymc-devs / pymc2

THIS IS THE **OLD** PYMC PROJECT (VERSION 2). PLEASE USE PYMC INSTEAD:
http://pymc-devs.github.com/pymc/
Other
879 stars 229 forks source link

Issue with degenerate beta binomial? #114

Closed kyleabeauchamp closed 8 years ago

kyleabeauchamp commented 8 years ago

In the limit of b -> 0, we expect (AFAIK) the beta binomial distribution to approach a delta distribution with E(x) = n a / (a + b) -> n. However, I find that the log likelihood of the beta binomial actually gives a discrete uniform when b=0. See driver code below and output figures of the pmf.

import numpy as np
import pymc as pm

a = 10.
n = 4
xgrid = np.arange(5)

for i, b in enumerate([1E-2, 1E-5, 0.0]):
  logprobs = np.array([pm.betabin_like(x, a, b, n) for x in xgrid])
  probs = np.exp(logprobs)
  plt.figure()
  plt.title(str(b))
  plt.plot(xgrid, probs, label=str(b))
  plt.ylim(-0.1, 1.1)
  plt.savefig("./%d.png" % i)

image

image

image

kyleabeauchamp commented 8 years ago

Tested on OSX + anaconda2.7 + pymc 2.3.6 + numpy 1.10.4

kyleabeauchamp commented 8 years ago

Also notice that the logP isn't even properly normalized in the case of b=0.0

kyleabeauchamp commented 8 years ago

AFAIK I think the relevant code is here:

https://github.com/pymc-devs/pymc/blob/master/pymc/flib.f#L4224

kyleabeauchamp commented 8 years ago

After applying PR #115, I get the following output from the above driver script:

0

1

2

kyleabeauchamp commented 8 years ago

Obviously this is stretching the notation a bit, as most people probably require positive values on the parameters. On the other hand, extending the domain a bit is probably better than silently return a wrong answer.

fonnesbeck commented 8 years ago

That's fine. The log-likelihoods were primarily intended to power MCMC, so simply returning -inf for parameters that are zero makes sense most of the time. The fact that negative a and b values are being admitted in some circumstances in the new code has me a little worried.

kyleabeauchamp commented 8 years ago

Good catch, see #116