SSJ
V. 1.2.5.

umontreal.iro.lecuyer.probdist
Class DistributionFactory

java.lang.Object
  extended by umontreal.iro.lecuyer.probdist.DistributionFactory

public class DistributionFactory
extends Object

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.

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).


Method Summary
static ContinuousDistribution getContinuousDistribution(String str)
          Uses the Java Reflection API to construct a ContinuousDistribution object by executing the code contained in the string str.
static DiscreteDistribution getDiscreteDistribution(String str)
          Same as getContinuousDistribution, but for discrete distributions over the real numbers.
static DiscreteDistributionInt getDiscreteDistributionInt(String str)
          Same as getContinuousDistribution, but for discrete distributions over the integers.
static ContinuousDistribution getDistribution(Class 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.
static DiscreteDistributionInt getDistribution(Class 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.
static Distribution getDistribution(String str)
           
static ContinuousDistribution getDistribution(String distName, 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.
static DiscreteDistributionInt getDistribution(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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDistribution

public static Distribution getDistribution(String str)

getDistribution

public static ContinuousDistribution getDistribution(String distName,
                                                     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.

Parameters:
distName - the name of the distribution to instanciate
x - the list of observations to use to evaluate parameters
n - the number of observations to use to evaluate parameters

getDistribution

public static DiscreteDistributionInt getDistribution(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.

Parameters:
distName - the name of the distribution to instanciate
x - the list of observations to use to evaluate parameters
n - the number of observations to use to evaluate parameters

getDistribution

public static ContinuousDistribution getDistribution(Class 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.

Parameters:
distClass - the class of the distribution to instanciate
x - the list of observations to use to evaluate parameters
n - the number of observations to use to evaluate parameters

getDistribution

public static DiscreteDistributionInt getDistribution(Class 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.

Parameters:
distClass - the class of the distribution to instanciate
x - the list of observations to use to evaluate parameters
n - the number of observations to use to evaluate parameters

getContinuousDistribution

public static ContinuousDistribution getContinuousDistribution(String str)
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:
str - string that contains a call to the constructor of a continuous distribution
Returns:
a continuous distribution object or null if it could not be instantiated
Throws:
IllegalArgumentException - if parsing problems occured when reading str
ClassCastException - if the distribution string does not represent a continuous distribution

getDiscreteDistribution

public static DiscreteDistribution getDiscreteDistribution(String str)
Same as getContinuousDistribution, but for discrete distributions over the real numbers.

Parameters:
str - string that contains a call to the constructor of a discrete distribution
Returns:
a discrete distribution object, or null if it could not be instantiated
Throws:
IllegalArgumentException - if parsing problems occured when reading str
ClassCastException - if the distribution string does not represent a discrete distribution

getDiscreteDistributionInt

public static DiscreteDistributionInt getDiscreteDistributionInt(String str)
Same as getContinuousDistribution, but for discrete distributions over the integers.

Parameters:
str - string that contains a call to the constructor of a discrete distribution
Returns:
a discrete distribution object, or null if it could not be instantiated
Throws:
IllegalArgumentException - if parsing problems occured when reading str
ClassCastException - if the distribution string does not represent a discrete distribution

SSJ
V. 1.2.5.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.