PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_rand_int_poisson_varmean (g05tk)
Purpose
nag_rand_int_poisson_varmean (g05tk) generates a vector of pseudorandom integers, each from a discrete Poisson distribution with differing parameter.
Syntax
Description
nag_rand_int_poisson_varmean (g05tk) generates
integers
, each from a discrete Poisson distribution with mean
, where the probability of
is
where
The methods used by this function have low set up times and are designed for efficient use when the value of the parameter
changes during the simulation. For large samples from a distribution with fixed
using
nag_rand_int_poisson (g05tj) to set up and use a reference vector may be more efficient.
When
the product of uniforms method is used, see for example
Dagpunar (1988). For larger values of
an envelope rejection method is used with a target distribution:
This distribution is generated using a ratio of uniforms method. A similar approach has also been suggested by
Ahrens and Dieter (1989). The basic method is combined with quick acceptance and rejection tests given by
Maclaren (1990). For values of
Stirling's approximation is used in the computation of the Poisson distribution function, otherwise tables of factorials are used as suggested by
Maclaren (1990).
One of the initialization functions
nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_int_poisson_varmean (g05tk).
References
Ahrens J H and Dieter U (1989) A convenient sampling method with bounded computation times for Poisson distributions Amer. J. Math. Management Sci. 1–13
Dagpunar J (1988) Principles of Random Variate Generation Oxford University Press
Maclaren N M (1990) A Poisson random number generator Personal Communication
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The means,
, for , of the Poisson distributions.
Constraint:
, for .
- 2:
– int64int32nag_int array
-
Note: the actual argument supplied
must be the array
state supplied to the initialization routines
nag_rand_init_repeat (g05kf) or
nag_rand_init_nonrepeat (g05kg).
Contains information on the selected base generator and its current state.
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the array
vlamda.
, the number of Poisson distributions for which pseudorandom variates are required.
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int array
-
Contains updated information on the state of the generator.
- 2:
– int64int32nag_int array
-
The pseudorandom numbers from the specified Poisson distributions.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
Constraint: .
-
-
On entry, at least one element of
vlamda is less than zero.
On entry, at least one element of
vlamda is too large.
-
-
On entry,
state vector has been corrupted or not initialized.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
None.
Example
This example prints ten pseudorandom integers from five Poisson distributions with means
,
,
,
and
. These are generated by ten calls to
nag_rand_int_poisson_varmean (g05tk), after initialization by
nag_rand_init_repeat (g05kf).
Open in the MATLAB editor:
g05tk_example
function g05tk_example
fprintf('g05tk example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
n = 10;
vlamda = [0.5; 5; 10; 500; 1000];
m = numel(vlamda);
x = zeros(n, m, 'int64');
for i = 1:n
[state, x(i, :), ifail] = g05tk( ...
vlamda, state);
end
disp('Variates');
disp(double(x));
g05tk example results
Variates
1 6 12 507 1003
0 9 11 520 1028
1 3 7 483 1041
0 3 11 513 1012
1 5 9 496 940
0 6 17 548 990
1 9 8 512 1035
0 4 10 458 1029
1 6 13 523 971
0 9 16 519 999
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015