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 uninformative geometric RV #120

Closed kyleabeauchamp closed 8 years ago

kyleabeauchamp commented 8 years ago

So I find that for small values of rho, the geometric RV can cause an exception. I understand that this is expected for rho=0. However, what surprised me was that for rho=1E-9, the random variable will actually fail to initialize stochastically. E.g. the variable creation will cause the following error 10% of the time.

import pymc as pm

rho = 1E-9

for i in range(100):
    x = pm.Geometric("x", rho)

[...]
# Prints i = 1, ... i = 10 or so then dies.
# e.g. RV seems to cause an overflow stochastically but with 10% probability.

ZeroProbability: Stochastic x's value is outside its support,
 or it forbids its parents' current values.

Do you find this failure mode surprising or expected?

fonnesbeck commented 8 years ago
>>> pm.geometric_like(0.1, rho)
-1.7976931348623157e+308
fonnesbeck commented 8 years ago

This is related to the initial value, which is chosen here as a random draw from a geometric with parameter rho. These values can be quite large:

In [13]: x = pm.rgeometric(rho, size=10000)

In [14]: x
Out[14]: 
array([ 504360309,  241731401,  416182498, ..., 1833893834,   22033398,
          8510115])

In [15]: x.max()
Out[15]: 8509440316

If you pass this as a value to the geometric, you get an overflow:

In [17]: pm.geometric_like(x.max(), rho)
Out[17]: -1.7976931348623157e+308
kyleabeauchamp commented 8 years ago

Sounds plausible to me: the logprob overflows before the random draws so extra care is needed near the boundaries of the feasible parameters.

fonnesbeck commented 8 years ago

I can use 64-bit integers, which should fix it.