SSJ  3.3.1
Stochastic Simulation in Java
Static Public Member Functions | List of all members
DistributionFactory Class Reference

This class implements a string API for the package probdist. More...

Static Public Member Functions

static Distribution getDistribution (String str)
 
static ContinuousDistribution getDistributionMLE (String distName, double[] x, int n)
 Uses the Java Reflection API to construct a ContinuousDistribution , DiscreteDistributionInt or DiscreteDistribution object, as specified by the string str. More...
 
static DiscreteDistributionInt getDistributionMLE (String distName, int[] x, int n)
 Uses the Java Reflection API to construct a DiscreteDistributionInt object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\). More...
 
static< T extends ContinuousDistribution > T getDistributionMLE (Class< T > distClass, double[] x, int n)
 Uses the Java Reflection API to construct a ContinuousDistribution object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\). More...
 
static< T extends DiscreteDistributionInt > T getDistributionMLE (Class< T > distClass, int[] x, int n)
 Uses the Java Reflection API to construct a DiscreteDistributionInt object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\). More...
 
static ContinuousDistribution getContinuousDistribution (String str)
 Uses the Java Reflection API to construct a ContinuousDistribution object by executing the code contained in the string str. More...
 
static DiscreteDistribution getDiscreteDistribution (String str)
 Same as getContinuousDistribution, but for discrete distributions over the real numbers. More...
 
static DiscreteDistributionInt getDiscreteDistributionInt (String str)
 Same as getContinuousDistribution, but for discrete distributions over the integers. More...
 

Detailed Description

This class implements a string API for the package probdist.

It uses Java Reflection to allow the creation of probability distribution objects from a string. This permits one to obtain distribution specifications from a file or dynamically from user input during program execution. This string API is similar to that of UNURAN [166] .

The (static) methods of this class invoke the constructor specified in the string. For example,

d = DistributionFactory.getContinuousDistribution ("NormalDist (0.0,
2.5)");

is equivalent to

d = NormalDist (0.0, 2.5);

The string that specifies the distribution (i.e., the formal parameter str of the methods) must be a valid call of the constructor of a class that extends ContinuousDistribution or DiscreteDistribution, and all parameter values must be numerical values (variable names are not allowed). If no parentheses follow, the default parameters are used, i.e. a no-parameter constructor is searched and invoked. Distribution parameters are surrounded with parentheses and are separated from each other using commas. The order and types of the parameters should be the same as the corresponding class constructor. When specifying decimal values, the dot should be used for decimal separation, not the comma. When specifying a float or a double, one can use -infinity or infinity to denote \(-\infty\) and \(+\infty\), respectively. This is parsed to Double.NEGATIVE_INFINITY and Double.POSITIVE_INFINITY, respectively. However, this is not accepted by all probability distributions.

For example, if one uses the string Normal, a NormalDist object with \(\mu= 0\) and \(\sigma= 1\) will be created. If one uses Exponential(2.5), an ExponentialDist object with \(\lambda=2.5\) will be constructed.

The distribution parameters can also be estimated from a set of observations instead of being passed to the constructor. In that case, one passes the vector of observations, and the constructor estimates the parameters by the maximum likelihood method.

Member Function Documentation

◆ getContinuousDistribution()

static ContinuousDistribution getContinuousDistribution ( String  str)
static

Uses the Java Reflection API to construct a ContinuousDistribution object by executing the code contained in the string str.

This code should be a valid invocation of the constructor of a ContinuousDistribution object. This method throws exceptions if it cannot parse the given string and returns null if the distribution object could not be created due to a Java-specific instantiation problem.

Parameters
strstring that contains a call to the constructor of a continuous distribution
Returns
a continuous distribution object or null if it could not be instantiated
Exceptions
IllegalArgumentExceptionif parsing problems occured when reading str
ClassCastExceptionif the distribution string does not represent a continuous distribution

◆ getDiscreteDistribution()

static DiscreteDistribution getDiscreteDistribution ( String  str)
static

Same as getContinuousDistribution, but for discrete distributions over the real numbers.

Parameters
strstring that contains a call to the constructor of a discrete distribution
Returns
a discrete distribution object, or null if it could not be instantiated
Exceptions
IllegalArgumentExceptionif parsing problems occured when reading str
ClassCastExceptionif the distribution string does not represent a discrete distribution

◆ getDiscreteDistributionInt()

static DiscreteDistributionInt getDiscreteDistributionInt ( String  str)
static

Same as getContinuousDistribution, but for discrete distributions over the integers.

Parameters
strstring that contains a call to the constructor of a discrete distribution
Returns
a discrete distribution object, or null if it could not be instantiated
Exceptions
IllegalArgumentExceptionif parsing problems occured when reading str
ClassCastExceptionif the distribution string does not represent a discrete distribution

◆ getDistributionMLE() [1/4]

static ContinuousDistribution getDistributionMLE ( String  distName,
double []  x,
int  n 
)
static

Uses the Java Reflection API to construct a ContinuousDistribution , DiscreteDistributionInt or DiscreteDistribution object, as specified by the string str.

This method throws exceptions if it cannot parse the given string and returns null if the distribution object simply could not be created due to a Java-specific instantiation problem.

Parameters
strdistribution specification string
Returns
a distribution object or null if it could not be instantiated
Exceptions
IllegalArgumentExceptionif parsing problems occured when reading str Uses the Java Reflection API to construct a ContinuousDistribution object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\).
Parameters
distNamethe name of the distribution to instanciate
xthe list of observations to use to evaluate parameters
nthe number of observations to use to evaluate parameters

◆ getDistributionMLE() [2/4]

static DiscreteDistributionInt getDistributionMLE ( String  distName,
int []  x,
int  n 
)
static

Uses the Java Reflection API to construct a DiscreteDistributionInt object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\).

Parameters
distNamethe name of the distribution to instanciate
xthe list of observations to use to evaluate parameters
nthe number of observations to use to evaluate parameters

◆ getDistributionMLE() [3/4]

static <T extends ContinuousDistribution> T getDistributionMLE ( Class< T >  distClass,
double []  x,
int  n 
)
static

Uses the Java Reflection API to construct a ContinuousDistribution object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\).

Parameters
distClassthe class of the distribution to instanciate
xthe list of observations to use to evaluate parameters
nthe number of observations to use to evaluate parameters

◆ getDistributionMLE() [4/4]

static <T extends DiscreteDistributionInt> T getDistributionMLE ( Class< T >  distClass,
int []  x,
int  n 
)
static

Uses the Java Reflection API to construct a DiscreteDistributionInt object by estimating parameters of the distribution using the maximum likelihood method based on the \(n\) observations in table \(x[i]\), \(i = 0, 1, …, n-1\).

Parameters
distClassthe class of the distribution to instanciate
xthe list of observations to use to evaluate parameters
nthe number of observations to use to evaluate parameters

The documentation for this class was generated from the following file: