Package nltk :: Module probability :: Class DictionaryProbDist
[hide private]
[frames] | no frames]

type DictionaryProbDist

source code

object --+    
         |    
 ProbDistI --+
             |
            DictionaryProbDist

A probability distribution whose probabilities are directly specified by a given dictionary. The given dictionary maps samples to probabilities.

Instance Methods [hide private]
 
__init__(self, prob_dict=None, log=False, normalize=False)
Construct a new probability distribution from the given dictionary, which maps values to probabilities (or to log probabilities, if log is true).
source code
float
prob(self, sample)
Returns: the probability for a given sample.
source code
float
logprob(self, sample)
Returns: the base 2 logarithm of the probability for a given sample.
source code
any
max(self)
Returns: the sample with the greatest probability.
source code
list
samples(self)
Returns: A list of all samples that have nonzero probabilities.
source code
 
__repr__(self) source code

Inherited from ProbDistI: discount, generate

Class Variables [hide private]

Inherited from ProbDistI: SUM_TO_ONE

Method Details [hide private]

__init__(self, prob_dict=None, log=False, normalize=False)
(Constructor)

source code 

Construct a new probability distribution from the given dictionary, which maps values to probabilities (or to log probabilities, if log is true). If normalize is true, then the probability values are scaled by a constant factor such that they sum to 1.

Overrides: ProbDistI.__init__

prob(self, sample)

source code 
Parameters:
  • sample - The sample whose probability should be returned.
Returns: float
the probability for a given sample. Probabilities are always real numbers in the range [0, 1].
Overrides: ProbDistI.prob
(inherited documentation)

logprob(self, sample)

source code 
Parameters:
  • sample - The sample whose probability should be returned.
Returns: float
the base 2 logarithm of the probability for a given sample. Log probabilities range from negitive infinity to zero.
Overrides: ProbDistI.logprob
(inherited documentation)

max(self)

source code 
Returns: any
the sample with the greatest probability. If two or more samples have the same probability, return one of them; which sample is returned is undefined.
Overrides: ProbDistI.max
(inherited documentation)

samples(self)

source code 
Returns: list
A list of all samples that have nonzero probabilities. Use prob to find the probability of each sample.
Overrides: ProbDistI.samples
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
Overrides: object.__repr__
(inherited documentation)