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

java.lang.Object
  extended by org.apache.mahout.math.PersistentObject
      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:
java.io.Serializable, java.lang.Cloneable, org.apache.mahout.math.function.DoubleFunction, IntFunction, UnaryFunction

public class NegativeBinomial
extends AbstractDiscreteDistribution

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

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.mahout.math.jet.random.AbstractDistribution
randomGenerator
 
Constructor Summary
NegativeBinomial(int r, double p, java.util.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.
 java.lang.Object clone()
          Deprecated. 
 int nextInt()
           
 int nextInt(int r, double p)
          Returns a sample from this distribution.
 double pdf(int k)
          Returns the probability distribution function.
 void setRandP(int r, double p)
          Sets the parameters number of trials and the probability of success.
 java.lang.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, setRandomGenerator
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NegativeBinomial

public NegativeBinomial(int r,
                        double p,
                        java.util.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.


clone

@Deprecated
public java.lang.Object clone()
Deprecated. 

Returns a deep copy of the receiver; the copy will produce identical sequences. After this call has returned, the copy and the receiver have equal but separate state.

Overrides:
clone in class org.apache.mahout.math.PersistentObject
Returns:
a copy of the receiver.

nextInt

public int nextInt()
Specified by:
nextInt in class AbstractDiscreteDistribution
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.


setRandP

public void setRandP(int r,
                     double p)
Sets the parameters number of trials and the probability of success.

Parameters:
r - the number of trials
p - the probability of success.

toString

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

Overrides:
toString in class java.lang.Object


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.