common
Class MultinomialWithTail

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

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

A mixture of a multinomial over the first k natural numbers 0,...,(k-1), and a geometric distribution over the numbers >= k. The parameter k is fixed at construction. The one free parameter is lambda = P(X < k).

See Also:
Serialized Form

Constructor Summary
MultinomialWithTail(double[] pi, double lambda, double alpha)
          Creates a MultinomialWithTail with the given array of probabilities for the multinomial distribution, and the given lambda and alpha values.
MultinomialWithTail(int k)
          Creates a MultinomialWithTail with the given k.
 
Method Summary
 void collectStats(int n)
          Records an occurrence of the number n, for use in updating parameters.
 double getLogProb(int n)
          Returns the log probability of the number n.
 double getProb(int n)
          Return probability of n
 int sample()
          Generates iid samples from this distribution
 double updateParams()
          Sets the parameter lambda to the value that maximizes the likelihood of the numbers 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

MultinomialWithTail

public MultinomialWithTail(int k)
Creates a MultinomialWithTail with the given k. The multinomial distribution is initially uniform, the geometric distribution has alpha = 0.5, and lambda is also initialized to 0.5.


MultinomialWithTail

public MultinomialWithTail(double[] pi,
                           double lambda,
                           double alpha)
Creates a MultinomialWithTail with the given array of probabilities for the multinomial distribution, and the given lambda and alpha values. k is set to the size of the probability array.

Parameters:
pi - an array of double values specifying a probability distribution over the first pi.length natural numbers
lambda - the probability P(X < pi.length)
alpha - the parameter of the geometric distribution: P(X >= n+1 | X >= n) for n >= pi.length
Method Detail

getLogProb

public double getLogProb(int n)
Returns the log probability of the number n.

Specified by:
getLogProb in interface IntegerDist

getProb

public double getProb(int n)
Return probability of n

Specified by:
getProb in interface IntegerDist

collectStats

public void collectStats(int n)
Records an occurrence of the number n, for use in updating parameters.


sample

public int sample()
Generates iid samples from this distribution

Specified by:
sample in interface IntegerDist

updateParams

public double updateParams()
Sets the parameter lambda to the value that maximizes the likelihood of the numbers 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.