nltk.probability.DictionaryProbDist¶
- class nltk.probability.DictionaryProbDist[source]¶
Bases:
ProbDistI
A probability distribution whose probabilities are directly specified by a given dictionary. The given dictionary maps samples to probabilities.
- __init__(prob_dict=None, log=False, normalize=False)[source]¶
Construct a new probability distribution from the given dictionary, which maps values to probabilities (or to log probabilities, if
log
is true). Ifnormalize
is true, then the probability values are scaled by a constant factor such that they sum to 1.If called without arguments, the resulting probability distribution assigns zero probability to all values.
- prob(sample)[source]¶
Return the probability for a given sample. Probabilities are always real numbers in the range [0, 1].
- Parameters
sample (any) – The sample whose probability should be returned.
- Return type
float
- logprob(sample)[source]¶
Return the base 2 logarithm of the probability for a given sample.
- Parameters
sample (any) – The sample whose probability should be returned.
- Return type
float
- max()[source]¶
Return 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.
- Return type
any
- samples()[source]¶
Return a list of all samples that have nonzero probabilities. Use
prob
to find the probability of each sample.- Return type
list
- SUM_TO_ONE = True¶
True if the probabilities of the samples in this probability distribution will always sum to one.