Module mixture :: Class DiscreteDistribution
[hide private]
[frames] | no frames]

Class DiscreteDistribution

source code


This is the special case of a MultinomialDistribution with p = 1, that is a simple univariate discrete distribution. Certain key functions are overloaded for increased efficiency.

Instance Methods [hide private]
 
__init__(self, M, phi, alphabet=None, parFix=None)
Constructor
source code
 
__str__(self)
String representation of the DataSet
source code
 
__copy__(self)
Interface for the copy.copy function
source code
 
pdf(self, data)
Density function.
source code
 
MStep(self, posterior, data, mix_pi=None)
Maximization step of the EM procedure.
source code
 
sample(self)
Samples a single value from the distribution.
source code
 
sampleSet(self, nr)
Samples several values from the distribution.
source code
 
sufficientStatistics(self, posterior, data)
Returns sufficient statistics for a given data set and posterior.
source code
 
formatData(self, x)
Formats samples 'x' for inclusion into DataSet object.
source code
 
isValid(self, x)
Checks whether 'x' is a valid argument for the distribution and raises InvalidDistributionInput exception if that is not the case.
source code
 
flatStr(self, offset)
Returns the model parameters as a string compatible with the WriteMixture/ReadMixture flat file format.
source code

Inherited from MultinomialDistribution: __eq__, merge, posteriorTraceback

Inherited from ProbDistribution: update_suff_p

Method Details [hide private]

__init__(self, M, phi, alphabet=None, parFix=None)
(Constructor)

source code 

Constructor

Parameters:
  • M - size of alphabet
  • phi - distribution parameters
  • alphabet - Alphabet object (optional)
  • parFix - list of flags to determine if any elements of phi should be fixed
Overrides: ProbDistribution.__init__

__str__(self)
(Informal representation operator)

source code 

String representation of the DataSet

Returns:
string representation
Overrides: ProbDistribution.__str__
(inherited documentation)

__copy__(self)

source code 

Interface for the copy.copy function

Overrides: ProbDistribution.__copy__
(inherited documentation)

pdf(self, data)

source code 

Density function. MUST accept either numpy or DataSet object of appropriate values. We use numpys as input for the atomar distributions for efficiency reasons (The cleaner solution would be to construct DataSet subset objects for the different features and we might switch over to doing that eventually).

Parameters:
  • data - DataSet object or numpy array
Returns:
log-value of the density function for each sample in 'data'
Overrides: ProbDistribution.pdf
(inherited documentation)

MStep(self, posterior, data, mix_pi=None)

source code 

Maximization step of the EM procedure. Reestimates the distribution parameters using the posterior distribution and the data.

MUST accept either numpy or DataSet object of appropriate values. numpys are used as input for the atomar distributions for efficiency reasons

Parameters:
  • posterior - posterior distribution of component membership
  • data - DataSet object or 'numpy' of samples
  • mix_pi - mixture weights, necessary for MixtureModels as components.
Overrides: ProbDistribution.MStep
(inherited documentation)

sample(self)

source code 

Samples a single value from the distribution.

Returns:
sampled value
Overrides: ProbDistribution.sample
(inherited documentation)

sampleSet(self, nr)

source code 

Samples several values from the distribution.

Parameters:
  • nr - number of values to be sampled.
Returns:
sampled values
Overrides: ProbDistribution.sampleSet
(inherited documentation)

sufficientStatistics(self, posterior, data)

source code 

Returns sufficient statistics for a given data set and posterior.

Parameters:
  • posterior - numpy vector of component membership posteriors
  • data - numpy vector holding the data
Returns:
list with dot(posterior, data) and dot(posterior, data**2)
Overrides: ProbDistribution.sufficientStatistics
(inherited documentation)

formatData(self, x)

source code 

Formats samples 'x' for inclusion into DataSet object. Used by DataSet.internalInit()

Parameters:
  • x - list of samples
Returns:
two element list: first element = dimension of self, second element = sufficient statistics for samples 'x'
Overrides: ProbDistribution.formatData
(inherited documentation)

isValid(self, x)

source code 

Checks whether 'x' is a valid argument for the distribution and raises InvalidDistributionInput exception if that is not the case.

Parameters:
  • x - single sample in external representation, i.e.. an entry of DataSet.dataMatrix
Returns:
True/False flag
Overrides: ProbDistribution.isValid
(inherited documentation)

flatStr(self, offset)

source code 

Returns the model parameters as a string compatible with the WriteMixture/ReadMixture flat file format.

Parameters:
  • offset - number of ' ' characters to be used in the flatfile.
Overrides: ProbDistribution.flatStr
(inherited documentation)