common
Class Geometric

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

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

A geometric distribution over the natural numbers 0, 1, 2,... It has a single parameter alpha, which equals P(X >= n+1 | X >= n). Thus an alpha close to 1 yields a relatively flat distribution, whereas an alpha close to 0 yields a distribution that decays quickly. The distribution is defined by: P(X = n) = (1 - alpha) alpha^n

See Also:
Serialized Form

Constructor Summary
Geometric()
          Creates a geometric distribution with alpha = 0.5.
Geometric(double alpha)
          Creates a geometric distribution with the given alpha parameter.
 
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 getLogProbGivenUpperBound(int n, int upper)
          Returns the log probability that X = n given that X <= upper.
 double getProb(int n)
          Returns the probability of the number n.
 double getProbGivenUpperBound(int n, int upper)
          Returns the probability that X = n given that X <= upper.
 int sample()
          Generate iid samples from this distribution
 double updateParams()
          Sets the parameter alpha 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

Geometric

public Geometric()
Creates a geometric distribution with alpha = 0.5.


Geometric

public Geometric(double alpha)
Creates a geometric distribution with the given alpha parameter. Throws an IllegalArgumentException if alpha < 0 or alpha >= 1.

Method Detail

getProb

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

Specified by:
getProb in interface IntegerDist

getLogProb

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

Specified by:
getLogProb in interface IntegerDist

getProbGivenUpperBound

public double getProbGivenUpperBound(int n,
                                     int upper)
Returns the probability that X = n given that X <= upper. The conditional distribution of X given X <= upper is called a truncated geometric distribution. P(X = n | X <= m) = (1 - alpha) * alpha^n / (1 - alpha^(m+1))


getLogProbGivenUpperBound

public double getLogProbGivenUpperBound(int n,
                                        int upper)
Returns the log probability that X = n given that X <= upper. The conditional distribution of X given X <= upper is called a truncated geometric distribution. P(X = n | X <= m) = (1 - alpha) * alpha^n / (1 - alpha^(m+1))


collectStats

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


updateParams

public double updateParams()
Sets the parameter alpha 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.


sample

public int sample()
Generate iid samples from this distribution

Specified by:
sample in interface IntegerDist