hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_rand_int_poisson_varmean (g05tk)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_rand_int_poisson_varmean (g05tk) generates a vector of pseudorandom integers, each from a discrete Poisson distribution with differing parameter.

Syntax

[state, x, ifail] = g05tk(vlamda, state, 'm', m)
[state, x, ifail] = nag_rand_int_poisson_varmean(vlamda, state, 'm', m)

Description

nag_rand_int_poisson_varmean (g05tk) generates m integers xj, each from a discrete Poisson distribution with mean λj, where the probability of xj=I is
P xj=I = λjI × e -λj I! ,   I=0,1, ,  
where
λj 0 ,   j=1,2,,m .  
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 λ<7.5 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:
fx=13 if ​x1, fx=13x-3 otherwise.  
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 λ87 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:     vlamdam – double array
The means, λj, for j=1,2,,m, of the Poisson distributions.
Constraint: 0.0vlamdajx02bb/2.0, for j=1,2,,m.
2:     state: 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:     m int64int32nag_int scalar
Default: the dimension of the array vlamda.
m, the number of Poisson distributions for which pseudorandom variates are required.
Constraint: m1.

Output Parameters

1:     state: int64int32nag_int array
Contains updated information on the state of the generator.
2:     xm int64int32nag_int array
The m pseudorandom numbers from the specified Poisson distributions.
3:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
Constraint: m1.
   ifail=2
On entry, at least one element of vlamda is less than zero.
On entry, at least one element of vlamda is too large.
   ifail=3
On entry, state vector has been corrupted or not initialized.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

Not applicable.

Further Comments

None.

Example

This example prints ten pseudorandom integers from five Poisson distributions with means λ1=0.5, λ2=5, λ3=10, λ4=500 and λ5=1000. These are generated by ten calls to nag_rand_int_poisson_varmean (g05tk), after initialization by nag_rand_init_repeat (g05kf).
function g05tk_example


fprintf('g05tk example results\n\n');

% Initialize the base generator to a repeatable sequence
seed  = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
                        genid, subid, seed);

% Number of sets of variates
n = 10;
% Parameters
vlamda = [0.5; 5; 10; 500; 1000];
m = numel(vlamda);

x = zeros(n, m, 'int64');

% Generate n sets of the m variates
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)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015