3.2 Overview of Generation Algorithms
As you can see, the name of the distribution followed by the letters RV designate the class names. Implementations of these classes extend the AbstractRVarable
class, which implements the RVariableIfc
interface. Users simply create and instance of the class and then use it to get a sequence of values that have the named probability distribution. In order to implement a new random variable (i.e. some random variable
that is not already implemented) you can extend the class
AbstractRVariable
. This provides a basic template for what is expected
in the implementation. However, it implies that you need to implement
all of the required interfaces. The key method to implement is the
protected generate()
method, which should return the generated random
value.
In almost all cases, the JSL utilizes the inverse transform method for generating random variates. Thus, there is a one to one mapping of the underlying pseudo-random number and the resulting random variate. Even in the case of distributions that do not have closed form inverse cumulative distribution functions, the JSL utilizes numerical methods to approximate the function whenever feasible. For example, the JSL uses a rational function approximation, see Cody (1969), to implement the inverse cumulative distribution function for the standard normal distribution. The inversion for the gamma distribution is based on Algorithm AS 91 for inverting the chi-squared distribution and exploiting its relationship with the gamma. The beta distribution also uses numerical methods to compute the cumulative distribution function as well as bi-section search to determine the inverse for cumulative distribution function.
The JSL implements the BernoulliRV
, DUniformRV
, GeometricRV
,
NegativeBinomialRV
, and ShiftedGeometricRV
classes using the methods
described in Chapter 2 of Rossetti (2015). While more efficient methods may be available, the
PoissonRV
and BinomialRV
distributions are implemented by searching the
probability mass functions. Both search methods use an approximation to
get close to the value of the inverse and then search up or down through
the cumulative distribution function. Because of this both distributions
use numerically stable methods to compute the cumulative distribution
function values. The DEmpiricalRV
class also searches through the
cumulative distribution function.