The org.bzdev.math.rv package
This package contains classes that implement random variables. For extensibility, these random-variable classes implement the interfaceRandomVariableRVOps
. There
are two additional interfaces:
-
RandomVariableRVOps
is implemented by random numbers that generate other random numbers. -
RandomVariableRVNOps
is implemented by random numbers that generate other random numbers that in turn generate numbers.
Aside from constructors and a few access methods for purposes such as
printing statistics, and methods to implement range restrictions, one
simply calls the next()
method to generate the next
random value. The random numbers are generated by using the class
StaticRandom
, which has only static members. A
range restriction may result in these static members being called
repeatedly until a value satisfying the range restriction is found. A
range restriction is useful when a tail of a distribution contains
values that are not legal. For example a Gaussian random variable with
a mean of 1.0 and a standard deviation of 0.1 can very rarely produce
a negative value. If a negative value is not appropriate, a range
restriction can be used to avoid having to code this case explicitly.
There are also a series of classes for random variables whose values are other random variables. This is useful for factory classes that need to configure a series of objects with random variables that have different distributions without having to modify the factory's methods.
The top-level classes for the class hierarchy are shown in the following figure:
The base class is named RandomVariable
and it has a type
parameter giving the type of the values it creates. This is an
abstract class. The classes BooleanRandomVariable
,
IntegerRandomVariable
, LongRandomVariable
, and
DoubleRandomVariable
are also abstract classes that eliminate the
need to use a type parameter, and with the exception
of BooleanRandomVariable
, each class implements range
restrictions and contains a method named rangeTestFailed that takes a
single argument of an appropriate type (int, long or double
respectively). The method rangeTestFailed should be called by code
that implements the method next() when a range restriction is
supported. Unless next is to return a value other than a boolean, int,
long, or double, subclasses implementing a new type of random variable
should be subclasses of either BooleanRandomVariable
,
IntegerRandomVariable
, LongRandomVariable
, or
DoubleRandomVariable
. There is one existing class in this
category: InterarrivalTimeRV
, which is a subclass of
LongRandomVariable
. InterarrivalTimeRV
restricts the
values a random variable generates to non-negative long integers. In
addition, it simplifies the use of generic types (for example, in the
package org.bzdev.devqsim.rv
).
The abstract
class RandomVariableRV
has two
type parameters. The first specifies a type T, and the second
specifies a random variable class RV that is a subclass of
RandomVariable<T>. The
class RandomVariableRVN
, which
is a subclass of RandomVariableRV<T,RV> restricts T to be a
subclass of Number. The
classes BooleanRandomVariableRV
,
IntegerRandomVariableRV
,
LongRandomVariableRV
, and
DoubleRandomVariableRV
have a single type parameter that gives the class of the random
variable that a call to next() should return. For example, the class
GaussianRVRV
is a subclass of
DoubleRandomVariableRV<GaussianRV>,
while GaussianRV
is a subclass of
DoubleRandomVariable
.
GaussianRVRV
takes two random
variables as arguments to its constructor, and these are used to
generate the arguments to the constructor
for GaussianRV
, and instance of which
is returned when next() is called on an instance
of GaussianRVRV
.
There are a number of classes to provide random variables with specific distributions. A partial class hierarchy is shown in the following figure:
These include are classes to produce random variables with a fixed distribution which provides a single value, a uniform distribution, and a deterministic distribution, for boolean, integer, long, and double values.
The classes GaussianRV
,
LogNormalRV
, and
ExpDistrRV
provide subclasses
of DoubleRandomVariable
for
Gaussian, log-norm. and exponential distributions. The class
InterarrivalTimeRV provides a class for interarrival times in which
time is represented by a long. Its subclasses are
BinomialIATimeRV, DeterminIATimeRV, FixedIATimeRV, GaussianIATimeRV,
PoissonIATimeRV, and UniformIATimeRV.
Similarly, the following figure shows a partial class hierarchy for random variables that generate other random variables:
These classes are used primarily with factories that initialize multiple objects, each with a random variable with a different distribution function.
One class does not fit the pattern described above:
GaussianRVs
.
This class creates a vector of correlated random variables.