Question

Suppose I have a list of probability distributions (the sum of this is 1). I want to use that list to create a ProbDistI object. How do I use the NLTK's ProbDistI class (under the probability module) to create an object that contains this distribution? I had looked under the documentation listed here (Link) and it looks like all the methods extract some value related to an object that already has a probability distribution.

Are there any examples that uses ProbDistI? I've looked all over and had trouble finding any resources online.

Thanks!

Was it helpful?

Solution

As far as I understand ProbDistI class is an interface, the other classes implement it. That is each distribution class must have the methods of ProbDistI interface like prob(), max() etc. You could look directly in code for it.

The reason it was made this way could be that a distribution in general is too complex to describe as an object, whereas the special cases of distributions are easier to describe. For example, you can initiate UniformProbDist class which implements ProbDistI.

from nltk.probability import UniformProbDist as U
UD=U([1,2,3,4])

Now you have a uniform distribution UD. with UD.prob(1) you get 0.25

Another example of a distribution class that implements ProbDistI is DictionaryProbDist. You can create the same distribution as in the previous example:

from nltk.probability import DictionaryProbDist as D
DD=D({1:0.25,2:0.25,3:0.25,4:0.25})
print D.prob(1)
>>> 0.25

For another ways to create a distribution you could look directly in code searching for lines like this:

class DictionaryProbDist(ProbDistI):

that is a class that implements the interface ProbDistI

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top