Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## sim.util.distribution
Class EmpiricalWalker

    java.lang.Object
      sim.util.distribution.AbstractDistribution
          sim.util.distribution.AbstractDiscreteDistribution
              sim.util.distribution.EmpiricalWalker

All Implemented Interfaces:
  java.io.Serializable

    public class EmpiricalWalker

extends AbstractDiscreteDistribution

Discrete Empirical distribution (pdf's can be specified).

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.

See Also:
  Serialized Form

Field Summary
`protected int[]` | `A`
`protected double[]` | `cdf`
`protected double[]` | `F`
`protected int` | `K`

Fields inherited from class sim.util.distribution.AbstractDistribution
`randomGenerator`

Constructor Summary
`EmpiricalWalker(double[] pdf, int interpolationType, MersenneTwisterFast randomGenerator)` Constructs an Empirical distribution.

Method Summary
`double` | `cdf(int k)` Returns the cumulative distribution function.
`int` | `nextInt()` Returns a random integer `k` with probability `pdf(k)`.
`double` | `pdf(int k)` Returns the probability distribution function.
`void` | `setState(double[] pdf, int interpolationType)` Sets the distribution parameters.
`void` | `setState2(double[] pdf)` Sets the distribution parameters.
`java.lang.String` | `toString()` Returns a String representation of the receiver.

Methods inherited from class sim.util.distribution.AbstractDiscreteDistribution
`nextDouble`

Methods inherited from class sim.util.distribution.AbstractDistribution
`apply, apply, getRandomGenerator, setRandomGenerator`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### K

    protected int K

### A

    protected int[] A

### F

    protected double[] F

### cdf

    protected double[] cdf

Constructor Detail

### EmpiricalWalker

    public EmpiricalWalker(double[] pdf,
                           int interpolationType,
                           MersenneTwisterFast randomGenerator)

  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 `pdf` must satisfy both of the following conditions
  - `0.0 <= pdf[i] : 0<=i<=pdf.length-1`
  - `0.0 < Sum(pdf[i]) : 0<=i<=pdf.length-1`

  Parameters:
    `pdf` - the probability distribution function.
    `interpolationType` - can be either `Empirical.NO_INTERPOLATION` or `Empirical.LINEAR_INTERPOLATION`.
    `randomGenerator` - a uniform random number generator.
  Throws:
    `java.lang.IllegalArgumentException` - if at least one of the three conditions above is violated.

Method Detail

### cdf

    public double cdf(int k)

  Returns the cumulative distribution function.

### nextInt

    public int nextInt()

  Returns a random integer `k` with probability `pdf(k)`.

  Specified by:
    `nextInt` in class `AbstractDiscreteDistribution`

### pdf

    public double pdf(int k)

  Returns the probability distribution function.

### setState

    public void setState(double[] pdf,
                         int interpolationType)

  Sets the distribution parameters. The `pdf` must satisfy all of the following conditions
  - `pdf != null && pdf.length > 0`
  - `0.0 <= pdf[i] : 0 < =i <= pdf.length-1`
  - `0.0 < Sum(pdf[i]) : 0 <=i <= pdf.length-1`

  Parameters:
    `pdf` - probability distribution function.
  Throws:
    `java.lang.IllegalArgumentException` - if at least one of the three conditions above is violated.

### setState2

    public void setState2(double[] pdf)

  Sets the distribution parameters. The `pdf` must satisfy both of the following conditions
  - `0.0 <= pdf[i] : 0 < =i <= pdf.length-1`
  - `0.0 < Sum(pdf[i]) : 0 <=i <= pdf.length-1`

  Parameters:
    `pdf` - probability distribution function.
  Throws:
    `java.lang.IllegalArgumentException` - if at least one of the three conditions above is violated.

### toString

    public java.lang.String toString()

  Returns a String representation of the receiver.

  Overrides:
    `toString` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD