org.apache.mahout.math.jet.random
Class NegativeBinomial

java.lang.Object
  extended by org.apache.mahout.math.function.DoubleFunction
      extended by org.apache.mahout.math.jet.random.AbstractDistribution
          extended by org.apache.mahout.math.jet.random.AbstractDiscreteDistribution
              extended by org.apache.mahout.math.jet.random.NegativeBinomial
All Implemented Interfaces:
IntFunction

public final class NegativeBinomial
extends AbstractDiscreteDistribution

Mostly deprecated until unit tests are in place. Until this time, this class/interface is unsupported.


Constructor Summary
NegativeBinomial(int r, double p, Random randomGenerator)
          Constructs a Negative Binomial distribution which describes the probability of getting a particular number of negative trials (k) before getting a fixed number of positive trials (r) where each positive trial has probability (p) of being successful.
 
Method Summary
 double cdf(int k)
          Returns the cumulative distribution function.
 int nextInt()
           
 int nextInt(int r, double p)
          Returns a sample from this distribution.
 double pdf(int k)
          Returns the probability distribution function.
 String toString()
          Returns a String representation of the receiver.
 
Methods inherited from class org.apache.mahout.math.jet.random.AbstractDiscreteDistribution
nextDouble
 
Methods inherited from class org.apache.mahout.math.jet.random.AbstractDistribution
apply, apply, getRandomGenerator, randomDouble, setRandomGenerator
 
Methods inherited from class org.apache.mahout.math.function.DoubleFunction
isDensifying
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NegativeBinomial

public NegativeBinomial(int r,
                        double p,
                        Random randomGenerator)
Constructs a Negative Binomial distribution which describes the probability of getting a particular number of negative trials (k) before getting a fixed number of positive trials (r) where each positive trial has probability (p) of being successful.

Parameters:
r - the required number of positive trials.
p - the probability of success.
randomGenerator - a uniform random number generator.
Method Detail

cdf

public double cdf(int k)
Returns the cumulative distribution function.


pdf

public double pdf(int k)
Returns the probability distribution function.


nextInt

public int nextInt()
Specified by:
nextInt in class AbstractDistribution
Returns:
A random number from the distribution; returns (int) Math.round(nextDouble()). Override this method if necessary.

nextInt

public int nextInt(int r,
                   double p)
Returns a sample from this distribution. The value returned will be the number of negative samples required before achieving r positive samples. Each successive sample is taken independently from a Bernouli process with probability p of success. The algorithm used is taken from J.H. Ahrens, U. Dieter (1974): Computer methods for sampling from gamma, beta, Poisson and binomial distributions, Computing 12, 223--246. This algorithm is essentially the same as described at http://en.wikipedia.org/wiki/Negative_binomial_distribution#Gamma.E2.80.93Poisson_mixture except that the notion of positive and negative outcomes is uniformly inverted. Because the inversion is complete and consistent, this definition is effectively identical to that defined on wikipedia.


toString

public String toString()
Returns a String representation of the receiver.

Overrides:
toString in class Object


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.