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)

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 mm integers xjxj, each from a discrete Poisson distribution with mean λjλj, where the probability of xj = Ixj=I is
P (xj = I) = ( λjI × eλj )/(I ! ) ,   I = 0,1, ,
P (xj=I) = λjI × e -λj I! ,   I=0,1, ,
where
λj 0 ,   j = 1,2,,m .
λ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λ<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:
f(x) = (1/3) if ​|x|1,
f(x) = (1/3)|x|3 otherwise.
f(x)=13 if ​|x|1, f(x)=13|x|-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λ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:     vlamda(m) – double array
m, the dimension of the array, must satisfy the constraint m1m1.
The means, λjλj, for j = 1,2,,mj=1,2,,m, of the Poisson distributions.
Constraint: 0.0vlamda(j)x02bb / 2.00.0vlamdajx02bb/2.0, for j = 1,2,,mj=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.
mm, the number of Poisson distributions for which pseudorandom variates are required.
Constraint: m1m1.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     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 updated information on the state of the generator.
2:     x(m) – int64int32nag_int array
The mm pseudorandom numbers from the specified Poisson distributions.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry, m < 1m<1.
  ifail = 2ifail=2
On entry, vlamda(j) < 0.0vlamdaj<0.0 for at least one value of jj.
On entry, 2 × vlamda(j) > x02bb()2×vlamdaj>x02bb() for at least one value of jj.
  ifail = 3ifail=3
On entry,state vector was not initialized or has been corrupted.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_rand_int_poisson_varmean_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
vlamda = [0.5; 5; 10; 500; 1000];
x = zeros(10, 5, 'int64');
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
% Generate n sets of the m variates
for i = 1:10
  [state, x(i, :), ifail] = nag_rand_int_poisson_varmean(vlamda, state);
end
 x
 

x =

  Columns 1 through 4

                    1                    6                   12                  507
                    0                    9                   11                  520
                    1                    3                    7                  483
                    0                    3                   11                  513
                    1                    5                    9                  496
                    0                    6                   17                  548
                    1                    9                    8                  512
                    0                    4                   10                  458
                    1                    6                   13                  523
                    0                    9                   16                  519

  Column 5

                 1003
                 1028
                 1041
                 1012
                  940
                  990
                 1035
                 1029
                  971
                  999


function g05tk_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
vlamda = [0.5; 5; 10; 500; 1000];
x = zeros(10, 5, 'int64');
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
% Generate n sets of the m variates
for i = 1:10
  [state, x(i, :), ifail] = g05tk(vlamda, state);
end
 x
 

x =

  Columns 1 through 4

                    1                    6                   12                  507
                    0                    9                   11                  520
                    1                    3                    7                  483
                    0                    3                   11                  513
                    1                    5                    9                  496
                    0                    6                   17                  548
                    1                    9                    8                  512
                    0                    4                   10                  458
                    1                    6                   13                  523
                    0                    9                   16                  519

  Column 5

                 1003
                 1028
                 1041
                 1012
                  940
                  990
                 1035
                 1029
                  971
                  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–2013