The IMSL_DISCR_TABLE function sets up table to generate pseudorandom numbers from a general discrete distribution.

This routine requires an IDL Advanced Math and Stats license. For more information, contact your sales or technical support representative.

IMSL_DISCR_TABLE sets up a table that IMSL_RAND_GEN_CONT uses to generate pseudorandom deviates from a discrete distribution. The distribution can be specified either by its probability function prf or by a vector of values of the cumulative probability function. Note that prf is not the cumulative probability distribution function. If the cumulative probabilities are already available in Cum_Probs, the only reason to call IMSL_DISCR_TABLE is to form an index vector in the upper portion of the result so as to speed up the generation of random deviates by the routine RAND_GEN_CONT.

Examples


Example 1

In this example, IMSL_DISCR_TABLE is used to set up a table to generate pseudorandom variates from the discrete distribution:

Pr(X = 1) = 0.05

Pr(X = 2) = 0.45

Pr(X = 3) = 0.31

Pr(X = 4) = 0.04

Pr(X = 5) = 0.15

In this example, we input the cumulative probabilities directly using keyword Cum_Probs and request 3 indexes to be computed (nndx = 4). Since the number of mass points is so small, the indexes would not have much effect on the speed of the generation of the random variates.

.RUN
FUNCTION prf, x
RETURN, 0
END
cum_probs = [.05, .5, .81, .85, 1]
cumpr = IMSL_DISCR_TABLE('PRF', 0.00001, 4, 1, 5, $
  CUM_PROBS = cum_probs)
PM, cumpr

IDL prints:

0.0500000
0.500000
0.810000
0.850000
1.00000
3.00000
1.00000
2.00000
5.00000

Example 2

IMSL_DISCR_TABLE is sets up a table to generate binomial variates with parameters 20 and 0.5. IMSL_BINOMIALPDF is used to compute the probabilities.

.RUN
FUNCTION prf, ix
  RETURN, IMSL_BINOMIALPDF(ix, 20, 0.5)
END
 
cumpr = IMSL_DISCR_TABLE('PRF', 0.00001, 12, 0, 21)
PM, cumpr
 
1.90735e-05
0.000200272
0.00128746
0.00590802
0.0206938
0.0576583
0.131587
0.251722
0.411901
0.588099
0.748278
0.868413
0.942342
0.979306
0.994092
0.998713
0.999800
0.999981
1.00000
11.0000
1.00000
7.00000
8.00000
9.00000
9.00000
10.0000
11.0000
11.0000
12.0000
13.0000
19.0000

Syntax


Result = IMSL_DISCR_TABLE(Prf, Del, Nndx, Imin, Nmass [, CUM_PROBS=array] [, /DOUBLE])

Return Value


Array, cumpr, of length nmass + nndx containing in the first nmass positions, the cumulative probabilities and in some of the remaining positions, indexes to speed access to the probabilities.

Arguments


Del

Maximum absolute error allowed in computing the cumulative probability. Probabilities smaller than del are ignored; hence, del should be a small positive number. If del is too small, however, cumpr (nmass – 1) must be exactly 1.0 since that value is compared to 1.0 – del.

Imin

Scalar containing the smallest value the random deviate can assume. By default, prf is evaluated at imin. If this value is less than del, imin is incremented by 1 and again prf is evaluated at imin. This process is continued until prf(imin) ≥ del. imin is output as this value and result(0) is output as prf(imin).

Nmass

Scalar containing the number of mass points in the distribution. Input, if keyword Cum_probs is used; otherwise, output. By default, nmass is the smallest integer such that prf(imin + nmass – 1) > 1.0 – del. nmass does include the points iminin + j for which prf(iminin + j) < del, for j = 0, 1, ..., iminout – iminin, where iminin denotes the input value of imin and iminout denotes its output value.

Nndx

The number of elements of cumpr available to be used as indexes. nndx must be greater than or equal to 1. In general, the larger nndx is, to within sixty or seventy percent of nmass, the more efficient the generation of random numbers using IMSL_RAND_GEN_DISCR will be.

Prf

A scalar string specifying a user-supplied function to compute the probability associated with each mass point of the distribution The argument to the function is the point at which the probability function is to be evaluated. The argument to the function can range from imin to the value at which the cumulative probability is greater than or equal to 1.0 - del.

Keywords


CUM_PROBS (optional)

One dimensional array of length nmass containing the cumulative probabilities to be used in computing the index portion of the result. If the keyword CUM_PROBS is used, prf is not used and may be a dummy function.

DOUBLE (optional)

If present and nonzero, double precision is used.

Version History


6.4

Introduced

See Also


IMSL_RAND_GEN_CONT, IMSL_RAND_GEN_DISCR