nltk/nltk — Issue #110: WittenBellProbDist doesn't support bins=None or bins=freqdist.B()
Author: alexrudnick
Created: 2012-01-17 06:26:18+00:00
State: open

What version of NLTK are you using? (See nltk.__version__). Please only
submit bug reports for the current version.
2.0b8

What steps will reproduce the problem? (e.g. include Python source code)

>>> from nltk.probability import WittenBellProbDist, FreqDist
>>> fd = FreqDist(["This", "is", "This", "Good"])
>>> WittenBellProbDist(fd)

or

>>> WittenBellProbDist(fd,3)

Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
WittenBellProbDist(fd,3)
File "C:\Python26\lib\site-packages\nltk\probability.py", line 1208, in
__init__
self._P0 = self._T / float(self._Z * (self._N + self._T))
ZeroDivisionError: float division

What is the expected output? What do you see instead?

No errors, and the line:
<WittenBellProbDist based on 3 samples>

Please use labels and text to provide additional information.

I believe the problem is in the __init__:
if bins == None:
bins = freqdist.B()
...
self._Z = bins - self._freqdist.B()

and then:
if self._N==0:
self._P0 = 1.0 / self._Z
else:
self._P0 = self._T / float(self._Z * (self._N + self._T))
so no matter what there is a divide by zero

Migrated from http://code.google.com/p/nltk/issues/detail?id=538