|
NAG[g05mzc] NAG[nag_rngs_gen_discrete] - Generates a vector of random integers from a general discrete distribution, seeds and generator number passed explicitly
|
|
Calling Sequence
g05mzc(mode, p, ip1, comp_type, x, igen, iseed, r, 'np'=np, 'n'=n, 'fail'=fail)
nag_rngs_gen_discrete(. . .)
Parameters
|
mode - integer;
|
|
|
On entry: a code for selecting the operation to be performed by the function:
|
|
Set up reference vector only.
|
|
Generate variates using reference vector set up in a prior call to nag_rngs_gen_discrete (g05mzc).
|
|
Set up reference vector and generate variates.
|
|
Constraint: . .
|
|
|
p - Vector(1..np, datatype=float[8]);
|
|
|
On entry: the PDF or CDF of the distribution.
|
|
|
ip1 - integer;
|
|
|
On entry: the value of the variate, assumed to be a whole number, to which the probability in corresponds.
|
|
|
comp_type - String;
|
|
|
On entry: indicates the type of information contained in p.
|
|
p contains a probability distribution function (PDF).
|
|
p contains a cumulative distribution function (CDF)
|
|
Constraint: "Nag_Compute_1" or "Nag_Compute_2". .
|
|
|
x - Vector(1..n, datatype=integer[kernelopts('wordsize')/8]);
|
|
|
On exit: contains pseudo-random numbers from the specified discrete distribution.
|
|
|
iseed - Vector(1.., datatype=integer[kernelopts('wordsize')/8]);
|
|
|
On entry: contains values which define the current state of the selected generator.
|
|
On exit: contains updated values defining the new state of the selected generator.
|
|
|
r - Vector(1.., datatype=float[8]);
|
|
|
On entry: if mode is set to , the reference vector from the previous call to nag_rngs_gen_discrete (g05mzc).
|
|
On exit: the reference vector.
|
|
|
'np'=np - integer; (optional)
|
|
|
On entry: the number of values supplied in p defining the PDF or CDF of the discrete distribution.
|
|
Constraint: . .
|
|
|
'n'=n - integer; (optional)
|
|
|
On entry: , the number of pseudo-random numbers to be generated.
|
|
Constraint: . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_rngs_gen_discrete (g05mzc) generates a vector of pseudo-random integers from a discrete distribution with a given PDF (probability density function) or CDF (cumulative distribution function) .
|
|
Description
|
|
nag_rngs_gen_discrete (g05mzc) generates a sequence of integers , from a discrete distribution defined by information supplied in p. This may either be the PDF or CDF of the distribution. A reference vector is first set up to contain the CDF of the distribution in its higher elements, followed by an index. The full specifications of the reference vector are as follows.
|
the number of elements of index, .
|
|
a check number to make sure that the values of ip1 and comp_type haven't changed when calling nag_rngs_gen_discrete (g05mzc) with .
|
|
.
|
|
the space available for indexing .
|
|
, for , the CDF.
|
|
, for .
|
Setting up the reference vector and subsequent generation of variates can each be performed by separate calls to nag_rngs_gen_discrete (g05mzc) or may be combined in a single call.
One of the initialization functions g05kbc (nag_rngs_init_repeatable) (for a repeatable sequence if computed sequentially) or g05kcc (nag_rngs_init_nonrepeatable) (for a non-repeatable sequence) must be called prior to the first call to nag_rngs_gen_discrete (g05mzc).
|
|
Error Indicators and Warnings
|
|
"NE_BAD_PARAM"
On entry, argument had an illegal value.
"NE_INT"
On entry, . Constraint: .
On entry, . Constraint: .
On entry, . Constraint: .
"NE_INTERNAL_ERROR"
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance.
"NE_NOT_INCREASING"
On entry, and the values in p are not all in non-descending order.
"NE_PREV_CALL"
comp_type is not the same as when r was set up in a previous call. Previous value of , .
np or ip1 is not the same as when r was set up in a previous call. Previous value of , . Previous value of , .
"NE_REAL_ARRAY_ELEM_CONS"
On entry, at least one element of the vector p is negative. The first found is at position , .
"NE_REAL_ARRAY_SUM"
On entry, the sum of the elements of p is not one. The difference from unity in the summation is: .
|
|
|
Examples
|
|
>
|
mode := 2:
np := 11:
ip1 := -5:
comp_type := "Nag_Compute_1":
n := 20:
igen := 1:
p := Vector([0.01, 0.02, 0.04, 0.08, 0.2, 0.3, 0.2, 0.08, 0.04, 0.02, 0.01], datatype=float[8]):
x := Vector(20, datatype=integer[kernelopts('wordsize')/8]):
iseed := Vector([1762543, 9324783, 42344, 742355], datatype=integer[kernelopts('wordsize')/8]):
r := Vector(23, datatype=float[8]):
NAG:-g05mzc(mode, p, ip1, comp_type, x, igen, iseed, r, 'np' = np, 'n' = n):
|
|
|