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 (g05tj)

Purpose

nag_rand_int_poisson (g05tj) generates a vector of pseudorandom integers from the discrete Poisson distribution with mean λλ.

Syntax

[r, state, x, ifail] = g05tj(mode, n, lambda, r, state)
[r, state, x, ifail] = nag_rand_int_poisson(mode, n, lambda, r, state)

Description

nag_rand_int_poisson (g05tj) generates nn integers xixi from a discrete Poisson distribution with mean λλ, where the probability of xi = Ixi=I is
P(xi = I) = (λI × eλ)/(I ! ),  I = 0,1,,
P(xi=I)= λI×e-λ I! ,  I=0,1,,
where λ0λ0.
The variates can be generated with or without using a search table and index. If a search table is used then it is stored with the index in a reference vector and subsequent calls to nag_rand_int_poisson (g05tj) with the same parameter values can then use this reference vector to generate further variates. The reference array is found using a recurrence relation if λλ is less than 5050 and by Stirling's formula otherwise.
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 (g05tj).

References

Kendall M G and Stuart A (1969) The Advanced Theory of Statistics (Volume 1) (3rd Edition) Griffin
Knuth D E (1981) The Art of Computer Programming (Volume 2) (2nd Edition) Addison–Wesley

Parameters

Compulsory Input Parameters

1:     mode – int64int32nag_int scalar
A code for selecting the operation to be performed by the function.
mode = 0mode=0
Set up reference vector only.
mode = 1mode=1
Generate variates using reference vector set up in a prior call to nag_rand_int_poisson (g05tj).
mode = 2mode=2
Set up reference vector and generate variates.
mode = 3mode=3
Generate variates without using the reference vector.
Constraint: mode = 0mode=0, 11, 22 or 33.
2:     n – int64int32nag_int scalar
nn, the number of pseudorandom numbers to be generated.
Constraint: n0n0.
3:     lambda – double scalar
λλ, the mean of the Poisson distribution.
Constraint: lambda0.0lambda0.0.
4:     r(lr) – double array
lr, the dimension of the array, must satisfy the constraint
  • if mode = 0mode=0 or 22,
    • if sqrt(lambda) > 7.15lambda>7.15, lr > 9 + int(8.5 + 14.3 × sqrt(lambda))lr>9+int(8.5+14.3×lambda);
    • otherwise lr > 9 + int(lambda + 7.15 × sqrt(lambda) + 8.5)lr>9+int(lambda+7.15×lambda+8.5);
  • if mode = 1mode=1, lr must remain unchanged from the previous call to nag_rand_int_poisson (g05tj).
If mode = 1mode=1, the reference vector from the previous call to nag_rand_int_poisson (g05tj).
If mode = 3mode=3, r is not referenced by nag_rand_int_poisson (g05tj).
5:     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

None.

Input Parameters Omitted from the MATLAB Interface

lr

Output Parameters

1:     r(lr) – double array
The reference vector.
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 updated information on the state of the generator.
3:     x(n) – int64int32nag_int array
The nn pseudorandom numbers from the specified Poisson distribution.
4:     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, mode0mode0, 11, 22 or 33.
  ifail = 2ifail=2
On entry, n < 0n<0.
  ifail = 3ifail=3
On entry, lambda < 0.0lambda<0.0.
mode = 0mode=0 or 22 and lambda is such that lr would have to be larger than the largest representable integer. Use mode = 3mode=3 in this case.
  ifail = 4ifail=4
On entry, lambda is not the same as when r was set up in a previous call to nag_rand_int_poisson (g05tj) with mode = 0mode=0 or 22.
On entry, the r vector was not initialized correctly, or has been corrupted.
  ifail = 5ifail=5
On entry, lr is too small when mode = 0mode=0 or 22.
  ifail = 6ifail=6
On entry,state vector was not initialized or has been corrupted.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_rand_int_poisson_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
mode = int64(2);
n = int64(10);
lambda = 20;
r = zeros(120, 1);
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
[r, state, x, ifail] = nag_rand_int_poisson(mode, n, lambda, r, state)
 

r =

   1.0e+03 *

    6.2845
    0.1205
    0.0200
         0
         0
    0.0615
   -0.0015
    0.0510
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0001
    0.0001
    0.0002
    0.0002
    0.0003
    0.0004
    0.0005
    0.0006
    0.0006
    0.0007
    0.0008
    0.0008
    0.0009
    0.0009
    0.0009
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0015
    0.0125
    0.0145
    0.0145
    0.0155
    0.0155
    0.0165
    0.0165
    0.0175
    0.0175
    0.0175
    0.0175
    0.0185
    0.0185
    0.0185
    0.0185
    0.0195
    0.0195
    0.0195
    0.0195
    0.0205
    0.0205
    0.0205
    0.0205
    0.0215
    0.0215
    0.0215
    0.0215
    0.0215
    0.0225
    0.0225
    0.0225
    0.0225
    0.0235
    0.0235
    0.0235
    0.0235
    0.0245
    0.0245
    0.0245
    0.0245
    0.0255
    0.0255
    0.0255
    0.0265
    0.0265
    0.0275
    0.0275
    0.0285
    0.0295
    0.0315


state =

                   17
                 1234
                    1
                    0
                 9910
                16740
                20386
                10757
                17917
                13895
                19930
                    8
                    0
                 1234
                    1
                    1
                 1234


x =

                   21
                   15
                   23
                   24
                   14
                   20
                   19
                   23
                   20
                   22


ifail =

                    0


function g05tj_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
mode = int64(2);
n = int64(10);
lambda = 20;
r = zeros(120, 1);
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
[r, state, x, ifail] = g05tj(mode, n, lambda, r, state)
 

r =

   1.0e+03 *

    6.2845
    0.1205
    0.0200
         0
         0
    0.0615
   -0.0015
    0.0510
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0000
    0.0001
    0.0001
    0.0002
    0.0002
    0.0003
    0.0004
    0.0005
    0.0006
    0.0006
    0.0007
    0.0008
    0.0008
    0.0009
    0.0009
    0.0009
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0010
    0.0015
    0.0125
    0.0145
    0.0145
    0.0155
    0.0155
    0.0165
    0.0165
    0.0175
    0.0175
    0.0175
    0.0175
    0.0185
    0.0185
    0.0185
    0.0185
    0.0195
    0.0195
    0.0195
    0.0195
    0.0205
    0.0205
    0.0205
    0.0205
    0.0215
    0.0215
    0.0215
    0.0215
    0.0215
    0.0225
    0.0225
    0.0225
    0.0225
    0.0235
    0.0235
    0.0235
    0.0235
    0.0245
    0.0245
    0.0245
    0.0245
    0.0255
    0.0255
    0.0255
    0.0265
    0.0265
    0.0275
    0.0275
    0.0285
    0.0295
    0.0315


state =

                   17
                 1234
                    1
                    0
                 9910
                16740
                20386
                10757
                17917
                13895
                19930
                    8
                    0
                 1234
                    1
                    1
                 1234


x =

                   21
                   15
                   23
                   24
                   14
                   20
                   19
                   23
                   20
                   22


ifail =

                    0



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