blog.distrib
Class Geometric

java.lang.Object
  extended by blog.AbstractCondProbDistrib
      extended by blog.distrib.Geometric
All Implemented Interfaces:
CondProbDistrib

public class Geometric
extends AbstractCondProbDistrib

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. Its mean is alpha / (1-alpha), so to get a distribution with mean m, one should use alpha = m / (1 + m).

Note that alpha cannot be 1, because then the value is infinite with probability 1. However, alpha can be 0; this just means the value is 0 with probability 1.


Constructor Summary
Geometric(double alpha)
          Creates a geometric distribution with the given alpha parameter.
Geometric(java.util.List params)
          Creates a geometric distribution with the given alpha parameter.
 
Method Summary
static Geometric constructWithMean(double mean)
          Returns a Geometric distribution with the given mean.
 double getLogProb(int n)
          Returns the natural log of the probability of the given integer under this distribution.
 double getLogProb(java.util.List args, java.lang.Object value)
          Returns the log probability of the given value, which should be an Integer.
 double getProb(int n)
          Returns the probability of the given integer under this distribution.
 double getProb(java.util.List args, java.lang.Object value)
          Returns the probability of the given value, which should be an Integer.
 int sampleVal()
          Returns an integer sampled from this distribution.
 java.lang.Object sampleVal(java.util.List args, Type childType)
          Generates a sample from this distribution.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Geometric

public Geometric(double alpha)
Creates a geometric distribution with the given alpha parameter.

Throws:
java.lang.IllegalArgumentException - if alpha is not in the range [0, 1)

Geometric

public Geometric(java.util.List params)
Creates a geometric distribution with the given alpha parameter.

Throws:
java.lang.IllegalArgumentException - if alpha < 0 or alpha >= 1.
Method Detail

constructWithMean

public static Geometric constructWithMean(double mean)
Returns a Geometric distribution with the given mean.


getProb

public double getProb(int n)
Returns the probability of the given integer under this distribution.


getProb

public double getProb(java.util.List args,
                      java.lang.Object value)
Returns the probability of the given value, which should be an Integer. Expects no arguments.


getLogProb

public double getLogProb(int n)
Returns the natural log of the probability of the given integer under this distribution.


getLogProb

public double getLogProb(java.util.List args,
                         java.lang.Object value)
Returns the log probability of the given value, which should be an Integer. Expects no arguments.

Specified by:
getLogProb in interface CondProbDistrib
Overrides:
getLogProb in class AbstractCondProbDistrib

sampleVal

public java.lang.Object sampleVal(java.util.List args,
                                  Type childType)
Generates a sample from this distribution. Expects no arguments.


sampleVal

public int sampleVal()
Returns an integer sampled from this distribution. Uses the method from p. 87 of Non-Uniform Random Variate Generation (by Luc Devroye, available at http://cg.scs.carleton.ca/~luc/rnbookindex.html), which exploits the fact that the geometric distribution can be seen as a discretization of the exponential distribution.


toString

public java.lang.String toString()
Overrides:
toString in class AbstractCondProbDistrib