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

Class ProbabilisticMixIn

source code

object --+
         |
        ProbabilisticMixIn
Known Subclasses:

A mix-in class to associate probabilities with other classes (trees, rules, etc.). To use the ProbabilisticMixIn class, define a new class that derives from an existing class and from ProbabilisticMixIn. You will need to define a new constructor for the new class, which explicitly calls the constructors of both its parent classes. For example:

>>> class A:
...     def __init__(self, x, y): self.data = (x,y)
... 
>>> class ProbabilisticA(A, ProbabilisticMixIn):
...     def __init__(self, x, y, **prob_kwarg):
...         A.__init__(self, x, y)
...         ProbabilisticMixIn.__init__(self, **prob_kwarg)

See the documentation for the ProbabilisticMixIn constructor for information about the arguments it expects.

You should generally also redefine the string representation methods, the comparison methods, and the hashing method.

Instance Methods [hide private]
 
__init__(self, **kwargs)
Initialize this object's probability.
source code
 
set_prob(self, prob)
Set the probability associated with this object to prob.
source code
 
set_logprob(self, logprob)
Set the log probability associated with this object to logprob.
source code
float
prob(self)
Returns: The probability associated with this object.
source code
float
logprob(self)
Returns: log(p), where p is the probability associated with this object.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **kwargs)
(Constructor)

source code 

Initialize this object's probability. This initializer should be called by subclass constructors. prob should generally be the first argument for those constructors.

Parameters:
  • prob (float) - The probability associated with the object.
  • logprob (float) - The log of the probability associated with the object.
Overrides: object.__init__

set_prob(self, prob)

source code 

Set the probability associated with this object to prob.

Parameters:
  • prob (float) - The new probability

set_logprob(self, logprob)

source code 

Set the log probability associated with this object to logprob. I.e., set the probability associated with this object to 2**(logprob).

Parameters:
  • logprob (float) - The new log probability

prob(self)

source code 
Returns: float
The probability associated with this object.

logprob(self)

source code 
Returns: float
log(p), where p is the probability associated with this object.