nag_rand_dirichlet (g05sec) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_rand_dirichlet (g05sec)

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rand_dirichlet (Nag_OrderType order, Integer n, Integer m, const double a[], Integer state[], double x[], Integer pdx, NagError *fail)

3  Description

The distribution has PDF (probability density function)
fx = 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.
nag_rand_dirichlet (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 nag_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_dirichlet (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:     orderNag_OrderTypeInput
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.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     nIntegerInput
On entry: n, the number of pseudorandom numbers to be generated.
Constraint: n0.
3:     mIntegerInput
On entry: m, the number of dimensions of the distribution.
Constraint: m>0.
4:     a[m]const doubleInput
On entry: the parameter vector for the distribution.
Constraint: a[i-1]>0.0, for i=1,2,,m.
5:     state[dim]IntegerCommunication 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]doubleOutput
Note: the dimension, dim, of the array x must be at least
  • max1,pdx×m when order=Nag_ColMajor;
  • max1,n×pdx when order=Nag_RowMajor.
Where Xi,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 Xi,j holding the jth dimension for the ith variate.
7:     pdxIntegerInput
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:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

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.
NE_INVALID_STATE
On entry, state vector has been corrupted or not initialized.
NE_REAL_ARRAY
On entry, at least one a[i]0.

7  Accuracy

Not applicable.

8  Parallelism and Performance

nag_rand_dirichlet (g05sec) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
Please 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 nag_rand_dirichlet (g05sec), after initialization by nag_rand_init_repeatable (g05kfc).

10.1  Program Text

Program Text (g05sece.c)

10.2  Program Data

None.

10.3  Program Results

Program Results (g05sece.r)


nag_rand_dirichlet (g05sec) (PDF version)
g05 Chapter Contents
g05 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2014