NAG CL Interface
g05sec (dist_​dirichlet)

Settings help

CL Name Style:


1 Purpose

g05sec generates a vector of pseudorandom numbers taken from a Dirichlet distribution.

2 Specification

#include <nag.h>
void  g05sec (Nag_OrderType order, Integer n, Integer m, const double a[], Integer state[], double x[], Integer pdx, NagError *fail)
The function may be called by the names: g05sec, nag_rand_dist_dirichlet or nag_rand_dirichlet.

3 Description

The distribution has PDF (probability density function)
f(x) = 1 B(α) i=1 m x i αi - 1 and B(α) = i=1 m Γ (αi) Γ ( i=1 m αi)  
where x = {x1,x2,,xm} is a vector of dimension m, such that xi>0 for all i and i=1 m xi=1.
g05sec generates a draw from a Dirichlet distribution by first drawing m independent samples, yigamma(αi,1), i.e., independent draws from a gamma distribution with parameters αi>0 and one, and then setting xi=yi/ j=1 m yj.
One of the initialization functions g05kfc (for a repeatable sequence if computed sequentially) or g05kgc (for a non-repeatable sequence) must be called prior to the first call to g05sec.

4 References

Dagpunar J (1988) Principles of Random Variate Generation Oxford University Press
Hastings N A J and Peacock J B (1975) Statistical Distributions Butterworth

5 Arguments

1: order Nag_OrderType Input
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section 3.1.3 in the Introduction to the NAG Library CL Interface for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2: n Integer Input
On entry: n, the number of pseudorandom numbers to be generated.
Constraint: n0.
3: m Integer Input
On entry: m, the number of dimensions of the distribution.
Constraint: m>0.
4: a[m] const double Input
On entry: the parameter vector for the distribution.
Constraint: a[i-1]>0.0, for i=1,2,,m.
5: state[dim] Integer Communication Array
Note: the dimension, dim, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument state in the previous call to nag_rand_init_repeatable (g05kfc) or nag_rand_init_nonrepeatable (g05kgc).
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.
6: x[dim] double Output
Note: the dimension, dim, of the array x must be at least
  • max(1,pdx×m) when order=Nag_ColMajor;
  • max(1,n×pdx) when order=Nag_RowMajor.
where X(i,j) appears in this document, it refers to the array element
  • x[(j-1)×pdx+i-1] when order=Nag_ColMajor;
  • x[(i-1)×pdx+j-1] when order=Nag_RowMajor.
On exit: the n pseudorandom numbers from the specified Dirichlet distribution, with X(i,j) holding the jth dimension for the ith variate.
7: pdx Integer Input
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
  • if order=Nag_ColMajor, pdxn;
  • if order=Nag_RowMajor, pdxm.
8: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, m=value.
Constraint: m > 0.
On entry, n=value.
Constraint: n0.
NE_INT_2
On entry, pdx=value and m=value.
Constraint: pdxm.
On entry, pdx=value and n=value.
Constraint: order=Nag_ColMajor or pdxn.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_INVALID_STATE
On entry, state vector has been corrupted or not initialized.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL_ARRAY
On entry, at least one a[i]0.

7 Accuracy

Not applicable.

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g05sec is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9 Further Comments

None.

10 Example

This example prints a set of five pseudorandom numbers from a Dirichlet distribution with parameters m=4 and α={2.0,2.0,2.0,2.0}, generated by a single call to g05sec, after initialization by g05kfc.

10.1 Program Text

Program Text (g05sece.c)

10.2 Program Data

None.

10.3 Program Results

Program Results (g05sece.r)