com.xj.anylogic.engine
Class CustomDistribution

java.lang.Object
  extended by com.xj.anylogic.engine.CustomDistribution
All Implemented Interfaces:
java.io.Serializable

public class CustomDistribution
extends java.lang.Object
implements java.io.Serializable

This class is used to generate random numbers from a probability density function (PDF) defined as a number of pairs (value,rate) with possible interpolation. You can supply the value and rate arrays directly, or construct a distribution from a TableFunction. Each draw requires a random number generator, so there are two different modes the CustomDistribution can work:
1. You do not provide the RNG in the constructor, but supply it each time you call get( Random ). In this case the CustomDistribution can safely be made static and shared across multiple models and objects.
2. You provide the RNG in the constructor, the RNG is then remembered in the CustomDistribution and you can use get() method without any parameters. This is simpler syntax, but such CustomDistribution cannot be shared between models with different RNGs used. The get( Random ) method can still be used in that case.

Author:
XJ Technologies Company Ltd. www.anylogic.com
See Also:
Serialized Form

Field Summary
static int INTERPOLATION_LINEAR
           
static int INTERPOLATION_NONE
           
static int INTERPOLATION_STEP
           
 
Constructor Summary
CustomDistribution(double[] observations)
          Constructs a custom empirical distribution from the given array of observations.
CustomDistribution(double[] values, double[] rates, int interpolationtype)
          Constructs a custom distribution from the given arrays of values and rates, and a given interpolation type.
CustomDistribution(double[] values, double[] rates, int interpolationtype, java.util.Random rng)
          Constructs a custom distribution from the given arrays of values and rates, and a given interpolation type.
CustomDistribution(double[] intervalStarts, int[] numberOfObservations)
          Constructs a custom empirical distribution from the given arrays of interval starts and number of observations found in the corresponding intervals.
CustomDistribution(double[] intervalStarts, int[] numberOfObservations, java.util.Random rng)
          Constructs a custom empirical distribution from the given arrays of interval starts and number of observations found in the corresponding intervals.
CustomDistribution(double[] observations, java.util.Random rng)
          Constructs a custom empirical distribution from the given array of observations.
CustomDistribution(int[] observations)
          Constructs a custom discrete empirical distribution from the given array of discrete observations.
CustomDistribution(int[] observations, java.util.Random rng)
          Constructs a custom discrete empirical distribution from the given array of discrete observations.
CustomDistribution(TableFunction table)
          Constructs a custom distribution from a given TableFunction.
CustomDistribution(TableFunction table, java.util.Random rng)
          Constructs a custom distribution from a given TableFunction.
 
Method Summary
 double get()
          Returns a random value distributed according to the given table of (value,rate) pairs.
 double get(double min, double max, double shift, double stretch)
          Generates a sample of truncated custom distribution.
 double get(double min, double max, double shift, double stretch, java.util.Random rng)
          Generates a sample of truncated custom distribution.
 double get(java.util.Random rng)
          Returns a random value distributed according to the given table of (value,rate) pairs.
 java.lang.String toString()
          Returns the textual representation of the custom distribution.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERPOLATION_NONE

public static final int INTERPOLATION_NONE
See Also:
Constant Field Values

INTERPOLATION_STEP

public static final int INTERPOLATION_STEP
See Also:
Constant Field Values

INTERPOLATION_LINEAR

public static final int INTERPOLATION_LINEAR
See Also:
Constant Field Values
Constructor Detail

CustomDistribution

public CustomDistribution(double[] intervalStarts,
                          int[] numberOfObservations)
Constructs a custom empirical distribution from the given arrays of interval starts and number of observations found in the corresponding intervals. Note that some arrays are used by reference and can be modified.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.

Parameters:
intervalStarts - the array of interval starts (2 or more, no duplicates, can be sorted or not), the last number is the end of the last interval
numberOfObservations - the array of observation counters (same size as values, no negative rates), the last number isn't actually used, it is assumed to be zero.

CustomDistribution

public CustomDistribution(double[] intervalStarts,
                          int[] numberOfObservations,
                          java.util.Random rng)
Constructs a custom empirical distribution from the given arrays of interval starts and number of observations found in the corresponding intervals. Note that some arrays are used by reference and can be modified.
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from ActiveObject or Experiment.

Parameters:
intervalStarts - the array of interval starts (2 or more, no duplicates, can be sorted or not), the last number is the end of the last interval
numberOfObservations - the array of observation counters (same size as values, no negative rates), the last number isn't actually used, it is assumed to be zero.
rng - the random number generator that will be used

CustomDistribution

public CustomDistribution(double[] values,
                          double[] rates,
                          int interpolationtype)
Constructs a custom distribution from the given arrays of values and rates, and a given interpolation type. Note that arrays are not copied; they are used by reference and can be modified.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.

Parameters:
values - the array of values (2 or more, no duplicates, can be sorted or not)
rates - the array of probability rates (same size as values, no negative rates)
interpolationtype - the interpolation type: INTERPOLATION_NONE, INTERPOLATION_STEP, or INTERPOLATION_LINEAR

CustomDistribution

public CustomDistribution(TableFunction table)
Constructs a custom distribution from a given TableFunction. Takes table function's interpolation type and check if it can be supported. Note that arrays are not copied: the table function arrays are used by reference.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.

Parameters:
table - the table function

CustomDistribution

public CustomDistribution(double[] values,
                          double[] rates,
                          int interpolationtype,
                          java.util.Random rng)
Constructs a custom distribution from the given arrays of values and rates, and a given interpolation type. Note that arrays are not copied; they are used by reference and can be modified.
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from ActiveObject or Experiment.

Parameters:
values - the array of values (2 or more, no duplicates, can be sorted or not)
rates - the array of probability rates (same size as values, no negative rates)
interpolationtype - the interpolation type: INTERPOLATION_NONE, INTERPOLATION_STEP, or INTERPOLATION_LINEAR
rng - the random number generator that will be used

CustomDistribution

public CustomDistribution(TableFunction table,
                          java.util.Random rng)
Constructs a custom distribution from a given TableFunction. Takes table function's interpolation type and check if it can be supported. Note that arrays are not copied: the table function arrays are used by reference.
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from ActiveObject or Experiment.

Parameters:
table - the table function
rng - the random number generator that will be used

CustomDistribution

public CustomDistribution(double[] observations)
Constructs a custom empirical distribution from the given array of observations. Note that array is used internally by reference and can be modified.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.

Parameters:
observations - the array of observed values (at least one value, can be sorted or not)

CustomDistribution

public CustomDistribution(double[] observations,
                          java.util.Random rng)
Constructs a custom empirical distribution from the given array of observations. Note that array is used internally by reference and can be modified.
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from ActiveObject or Experiment.

Parameters:
observations - the array of observed values (at least one value, can be sorted or not)
rng - the random number generator that will be used

CustomDistribution

public CustomDistribution(int[] observations)
Constructs a custom discrete empirical distribution from the given array of discrete observations. Note that array is used internally by reference and can be modified.
The random number generator is not set after this constructor and must then be provided in each call of get( Random ) method.

Parameters:
observations - the array of observed values (at least one value, can be sorted or not)

CustomDistribution

public CustomDistribution(int[] observations,
                          java.util.Random rng)
Constructs a custom discrete empirical distribution from the given array of discrete observations. Note that array is used internally by reference and can be modified.
The random number generator is set after this constructor, so you can use both get() and get( Random ) methods. The default RNG can be accessed as getDefaultRandomGenerator() if called from ActiveObject or Experiment.

Parameters:
observations - the array of observed values (at least one value, can be sorted or not)
Method Detail

get

public double get(java.util.Random rng)
Returns a random value distributed according to the given table of (value,rate) pairs. This method requires a random number generator. If you are calling it from an ActiveObject or an Experiment and wish to use the default RNG of the simulation engine you may write get( getDefaultRandomGenerator() ).

Parameters:
rng - the random number generator to be used.
Returns:
the random value

get

public double get()
Returns a random value distributed according to the given table of (value,rate) pairs. This method uses the random number generator set during construction and throws exception if no RNG was set.

Returns:
the random value

get

public double get(double min,
                  double max,
                  double shift,
                  double stretch,
                  java.util.Random rng)
Generates a sample of truncated custom distribution.
This method requires a random number generator. If you are calling it from an ActiveObject or an Experiment and wish to use the default RNG of the simulation engine you may write get( getDefaultRandomGenerator() ).
This distribution is sketched by sketch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see get(Random)

Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use Double.NEGATIVE_INFINITY for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use Double.POSITIVE_INFINITY for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
rng - the random number generator.
Returns:
the generated sample

get

public double get(double min,
                  double max,
                  double shift,
                  double stretch)
Generates a sample of truncated custom distribution.
This method uses the random number generator set during construction and throws exception if no RNG was set.
This distribution is sketched by sketch coefficient, then shifted to the right by shift, after that it is truncated to fit in [min, max] interval. Truncation is performed by discarding every sample outside this interval and taking subsequent try.
For more details see get()

Parameters:
min - the minimum value that this function will return. The distribution is truncated to return values above this. If the sample (stretched and shifted) is below this value it will be discarded and another sample will be drawn. Use Double.NEGATIVE_INFINITY for "No limit".
max - the maximum value that this function will return. The distribution is truncated to return values below this. If the sample (stretched and shifted) is bigger than this value it will be discarded and another sample will be drawn. Use Double.POSITIVE_INFINITY for "No limit".
shift - the shift parameter that indicates how much the (stretched) distribution will shifted to the right
stretch - the stretch parameter that indicates how much the distribution will be stretched
Returns:
the generated sample

toString

public java.lang.String toString()
Returns the textual representation of the custom distribution.

Overrides:
toString in class java.lang.Object
Returns:
the textual representation of the custom distribution


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.