IMSL Statistics Reference Guide > Random Number Generation > DISCR_TABLE Function (PV-WAVE Advantage)
  

DISCR_TABLE Function (PV-WAVE Advantage)
Sets up table to generate pseudorandom numbers from a general discrete distribution.
Usage
result = DISCR_TABLE(prf, del, nndx, imin, nmass)
Input Parameters
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.
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.
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 RAND_GEN_DISCR will be.
Input/Out Parameters
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, ..., iminoutiminin, where iminin denotes the input value of imin and iminout denotes its output value.
Returned Value
result—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.
Input Keywords
Double—If present and nonzero, double precision is used.
Cum_Probs—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.
Discussion
DISCR_TABLE sets up a table that RAND_GEN_CONT Function (PV-WAVE Advantage) 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 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.
Example 1
In this example, 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.
FUNCTION PRF, x
   RETURN, 0
END
cum_probs = [.05, .5, .81, .85, 1]
cumpr = DISCR_TABLE('PRF', 0.00001, 4, 1, 5, $
   cum_probs = cum_probs)
PM, cumpr 
; PV-WAVE prints the following:
; 0.0500000
; 0.500000
; 0.810000
; 0.850000
; 1.00000
; 3.00000
; 1.00000
; 2.00000
; 5.00000
Example 2
DISCR_TABLE is sets up a table to generate binomial variates with parameters 20 and 0.5. BINOMIALPDF is used to compute the probabilities.
FUNCTION PRF, ix
   RETURN,  BINOMIALPDF(ix, 20, 0.5)
END
cumpr = DISCR_TABLE('PRF', 0.00001, 12, 0, 21)
PM, cumpr ; PV-WAVE prints the following:
; 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

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.