/** * Constructs an Empirical distribution. The probability distribution * function (pdf) is an array of positive real numbers. It need not be * provided in the form of relative probabilities, absolute probabilities * are also accepted. The <tt>pdf</tt> must satisfy both of the following * conditions * <ul> * <li><tt>0.0 <= pdf[i] : 0<=i<=pdf.length-1</tt> * <li><tt>0.0 < Sum(pdf[i]) : 0<=i<=pdf.length-1</tt> * </ul> * * @param pdf * the probability distribution function. * @param interpolationType * can be either <tt>Empirical.NO_INTERPOLATION</tt> or * <tt>Empirical.LINEAR_INTERPOLATION</tt>. * @param randomGenerator * a uniform random number generator. * @throws IllegalArgumentException * if at least one of the three conditions above is violated. */ public EmpiricalWalker(double[] pdf, int interpolationType, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setState(pdf, interpolationType); setState2(pdf); }

/** * Constructs an Empirical distribution. The probability distribution * function (pdf) is an array of positive real numbers. It need not be * provided in the form of relative probabilities, absolute probabilities * are also accepted. The <tt>pdf</tt> must satisfy both of the following * conditions * <ul> * <li><tt>0.0 <= pdf[i] : 0<=i<=pdf.length-1</tt> * <li><tt>0.0 < Sum(pdf[i]) : 0<=i<=pdf.length-1</tt> * </ul> * * @param pdf * the probability distribution function. * @param interpolationType * can be either <tt>Empirical.NO_INTERPOLATION</tt> or * <tt>Empirical.LINEAR_INTERPOLATION</tt>. * @param randomGenerator * a uniform random number generator. * @throws IllegalArgumentException * if at least one of the three conditions above is violated. */ public EmpiricalWalker(double[] pdf, int interpolationType, DoubleRandomEngine randomGenerator) { setRandomGenerator(randomGenerator); setState(pdf, interpolationType); setState2(pdf); }

## Javadoc

The probability distribution function (pdf) must be provided by the user as an array of positive real numbers. The pdf does not need to be provided in the form of relative probabilities, absolute probabilities are also accepted.

Instance methods operate on a user supplied uniform random number generator; they are unsynchronized. Static methods operate on a default uniform random number generator; they are synchronized.

**Implementation:** Walker's algorithm. Generating a random number takes
O(1), i.e. constant time, as opposed to commonly used algorithms
with logarithmic time complexity. Preprocessing time (on object construction)
is O(k) where k is the number of elements of the provided
empirical pdf. Space complexity is O(k).

This is a port of discrete.c which was written by James Theiler and is distributed with GSL 0.4.1. Theiler's implementation in turn is based upon

Alastair J. Walker, An efficient method for generating discrete random variables with general distributions, ACM Trans Math Soft 3, 253-256 (1977).

See also: D. E. Knuth, The Art of Computer Programming, Volume 2 (Seminumerical algorithms), 3rd edition, Addison-Wesley (1997), p120.

## Most used methods

- setRandomGenerator
- setStateSets the distribution parameters. The pdf must satisfy all of the following conditions * pdf != null
- setState2Sets the distribution parameters. The pdf must satisfy both of the following conditions * 0.0 <= pdf

## Popular in Java

- Making http requests using okhttp
- onRequestPermissionsResult (Fragment)
- runOnUiThread (Activity)
- addToBackStack (FragmentTransaction)
- SecureRandom (java.security)This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
- DateFormat (java.text)Formats or parses dates and times.This class provides factories for obtaining instances configured f
- Callable (java.util.concurrent)A task that returns a result and may throw an exception. Implementors define a single method with no
- Stream (java.util.stream)A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
- XPath (javax.xml.xpath)XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
- IsNull (org.hamcrest.core)Is the value null?
- Top 12 Jupyter Notebook extensions