common
Class Multinomial

java.lang.Object
  extended by common.Multinomial
All Implemented Interfaces:
IntegerDist, java.io.Serializable

public class Multinomial
extends java.lang.Object
implements java.io.Serializable, IntegerDist

A distribution over a finite set of elements 0, 1, ..., k, specified with an array of k probabilities pi_0,...,pi_k summing to 1.

See Also:
Serialized Form

Constructor Summary
Multinomial(double[] pi)
          Creates a Multinomial object with probabilities specified by the given array.
Multinomial(int k)
          Creates a Multinomial object representing the uniform distribution over k elements.
 
Method Summary
 void collectAggrStats(int i, int n)
          Records n occurrences of an element i, for use in updating parameters.
 void collectStats(int i)
          Records an occurrence of element i, for use in updating parameters.
 double getLogProb(int i)
          Returns the log of the probability of element i.
 double getProb(int i)
          Returns the probability of element i.
 int sample()
          Returns an integer chosen at random according to this distribution.
 int size()
          Returns the size of the set that this distribution is defined over.
 double updateParams()
          Sets the parameter array pi to the values that maximize the likelihood of the elements passed to collectStats since the last call to updateParams.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Multinomial

public Multinomial(int k)
Creates a Multinomial object representing the uniform distribution over k elements.


Multinomial

public Multinomial(double[] pi)
Creates a Multinomial object with probabilities specified by the given array.

Throws:
java.lang.IllegalArgumentException - if pi does not define a probability distribution
Method Detail

size

public int size()
Returns the size of the set that this distribution is defined over.


getProb

public double getProb(int i)
Returns the probability of element i.

Specified by:
getProb in interface IntegerDist

getLogProb

public double getLogProb(int i)
Returns the log of the probability of element i.

Specified by:
getLogProb in interface IntegerDist

collectStats

public void collectStats(int i)
Records an occurrence of element i, for use in updating parameters.


collectAggrStats

public void collectAggrStats(int i,
                             int n)
Records n occurrences of an element i, for use in updating parameters.


updateParams

public double updateParams()
Sets the parameter array pi to the values that maximize the likelihood of the elements passed to collectStats since the last call to updateParams. Then clears the collected statistics, and returns the difference between the log likelihood of the data under the new parameters and the log likelihood under the old parameters.


sample

public int sample()
Returns an integer chosen at random according to this distribution.

Specified by:
sample in interface IntegerDist