Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

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 m$m$ exponential distributions each having a mean ai${a}_{i}$ and weight wi${w}_{i}$.

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)wie − x / ai i = 1
if ​x0,
f(x) = 0 otherwise,
$f(x) = ∑i=1m 1ai wi e-x/ai if ​x≥0, f(x) = 0 otherwise,$
where i = 1mwi = 1$\sum _{i=1}^{m}{w}_{i}=1$ and ai > 0${a}_{i}>0$, wi0${w}_{i}\ge 0$.
nag_rand_dist_expmix (g05sg) returns the values xi${x}_{i}$ by selecting, with probability wj${w}_{j}$, random variates from an exponential distribution with parameter aj${a}_{j}$.
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
n$n$, the number of pseudorandom numbers to be generated.
Constraint: n0${\mathbf{n}}\ge 0$.
2:     a(nmix) – double array
nmix, the dimension of the array, must satisfy the constraint nmix1${\mathbf{nmix}}\ge 1$.
The m$m$ parameters ai${a}_{i}$ for the m$m$ exponential distributions in the mix.
Constraint: a(i) > 0.0${\mathbf{a}}\left(\mathit{i}\right)>0.0$, for i = 1,2,,nmix$\mathit{i}=1,2,\dots ,{\mathbf{nmix}}$.
3:     wgt(nmix) – double array
nmix, the dimension of the array, must satisfy the constraint nmix1${\mathbf{nmix}}\ge 1$.
The m$m$ weights wi${w}_{i}$ for the m$m$ exponential distributions in the mix.
Constraints:
• i = 1mwgt(i) = 1.0$\sum _{\mathit{i}=1}^{m}{\mathbf{wgt}}\left(\mathit{i}\right)=1.0$;
• wgt(i)0.0${\mathbf{wgt}}\left(\mathit{i}\right)\ge 0.0$, for i = 1,2,,m$\mathit{i}=1,2,\dots ,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.)
m$m$, the number of exponential distributions in the mix.
Constraint: nmix1${\mathbf{nmix}}\ge 1$.

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 n$n$ pseudorandom numbers from the specified exponential mix distribution.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{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${\mathbf{ifail}}=1$
On entry, n < 0${\mathbf{n}}<0$.
ifail = 2${\mathbf{ifail}}=2$
On entry, nmix0${\mathbf{nmix}}\le 0$.
ifail = 3${\mathbf{ifail}}=3$
On entry, a(i)0.0${\mathbf{a}}\left(i\right)\le 0.0$ for at least one a(i)${\mathbf{a}}\left(i\right)$.
ifail = 4${\mathbf{ifail}}=4$
On entry, wgt(i) < 0.0${\mathbf{wgt}}\left(i\right)<0.0$ for at least one wgt(i)${\mathbf{wgt}}\left(i\right)$.
On entry, i = 1nmixwgt(i)1.0$\sum _{i=1}^{{\mathbf{nmix}}}{\mathbf{wgt}}\left(i\right)\ne 1.0$.
ifail = 5${\mathbf{ifail}}=5$
 On entry, state vector was not initialized or has been corrupted.

Not applicable.

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

```