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_dist_expmix (g05sg)

Purpose

nag_rand_dist_expmix (g05sg) generates a vector of pseudorandom numbers from an exponential mix distribution composed of mm exponential distributions each having a mean aiai and weight wiwi.

Syntax

[state, x, ifail] = g05sg(n, a, wgt, state, 'nmix', nmix)
[state, x, ifail] = nag_rand_dist_expmix(n, a, wgt, state, 'nmix', nmix)

Description

The distribution has PDF (probability density function)
m
f(x) = 1/(ai)wiex / ai
i = 1
if ​x0,
f(x) = 0 otherwise,
f(x) = i=1m 1ai wi e-x/ai if ​x0, f(x) = 0 otherwise,
where i = 1mwi = 1i=1mwi=1 and ai > 0ai>0, wi0wi0.
nag_rand_dist_expmix (g05sg) returns the values xixi by selecting, with probability wjwj, random variates from an exponential distribution with parameter ajaj.
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_dist_expmix (g05sg).

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:     n – int64int32nag_int scalar
nn, the number of pseudorandom numbers to be generated.
Constraint: n0n0.
2:     a(nmix) – double array
nmix, the dimension of the array, must satisfy the constraint nmix1nmix1.
The mm parameters aiai for the mm exponential distributions in the mix.
Constraint: a(i) > 0.0ai>0.0, for i = 1,2,,nmixi=1,2,,nmix.
3:     wgt(nmix) – double array
nmix, the dimension of the array, must satisfy the constraint nmix1nmix1.
The mm weights wiwi for the mm exponential distributions in the mix.
Constraints:
  • i = 1mwgt(i) = 1.0i=1mwgti=1.0;
  • wgt(i)0.0wgti0.0, for i = 1,2,,mi=1,2,,m.
4:     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:     nmix – int64int32nag_int scalar
Default: The dimension of the arrays a, wgt. (An error is raised if these dimensions are not equal.)
mm, the number of exponential distributions in the mix.
Constraint: nmix1nmix1.

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(n) – double array
The nn pseudorandom numbers from the specified exponential mix distribution.
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, n < 0n<0.
  ifail = 2ifail=2
On entry, nmix0nmix0.
  ifail = 3ifail=3
On entry, a(i)0.0ai0.0 for at least one a(i)ai.
  ifail = 4ifail=4
On entry, wgt(i) < 0.0wgti<0.0 for at least one wgt(i)wgti.
On entry, i = 1nmixwgt(i)1.0i=1nmixwgti1.0.
  ifail = 5ifail=5
On entry,state vector was not initialized or has been corrupted.

Accuracy

Not applicable.

Further Comments

None.

Example

function nag_rand_dist_expmix_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
n = int64(5);
a = [1; 5; 2];
wgt = [0.5; 0.3; 0.2];
% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(genid, subid, seed);
[state, x, ifail] = nag_rand_dist_expmix(n, a, wgt, state)
 

state =

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


x =

    0.4520
    2.2398
    1.4649
    0.2253
   11.2884


ifail =

                    0


function g05sg_example
% Initialize the seed
seed = [int64(1762543)];
% genid and subid identify the base generator
genid = int64(1);
subid =  int64(1);
n = int64(5);
a = [1; 5; 2];
wgt = [0.5; 0.3; 0.2];
% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(genid, subid, seed);
[state, x, ifail] = g05sg(n, a, wgt, state)
 

state =

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


x =

    0.4520
    2.2398
    1.4649
    0.2253
   11.2884


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