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

Class MutableProbDist

source code

object --+    
         |    
 ProbDistI --+
             |
            MutableProbDist

An mutable probdist where the probabilities may be easily modified. This simply copies an existing probdist, storing the probability values in a mutable dictionary and providing an update method.

Instance Methods [hide private]
 
__init__(self, prob_dist, samples, store_logs=True)
Creates the mutable probdist based on the given prob_dist and using the list of samples given.
source code
list
samples(self)
Returns: A list of all samples that have nonzero probabilities.
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
 
update(self, sample, prob, log=True)
Update the probability for the given sample.
source code

Inherited from ProbDistI: discount, generate, max

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]

Inherited from ProbDistI: SUM_TO_ONE

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, prob_dist, samples, store_logs=True)
(Constructor)

source code 

Creates the mutable probdist based on the given prob_dist and using the list of samples given. These values are stored as log probabilities if the store_logs flag is set.

Parameters:
  • prob_dist (ProbDist) - the distribution from which to garner the probabilities
  • samples (sequence of any) - the complete set of samples
  • store_logs (bool) - whether to store the probabilities as logarithms
Overrides: ProbDistI.__init__

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)

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)

update(self, sample, prob, log=True)

source code 

Update the probability for the given sample. This may cause the object to stop being the valid probability distribution - the user must ensure that they update the sample probabilities such that all samples have probabilities between 0 and 1 and that all probabilities sum to one.

Parameters:
  • sample (any) - the sample for which to update the probability
  • prob (float) - the new probability
  • log (bool) - is the probability already logged