# naginterfaces.library.rand.int_​multinomial¶

naginterfaces.library.rand.int_multinomial(mode, n, m, p, statecomm, comm=None)[source]

int_multinomial generates a sequence of variates, each consisting of pseudorandom integers, from the discrete multinomial distribution with outcomes and trials, where the outcomes have probabilities respectively.

For full information please refer to the NAG Library document for g05tg

https://www.nag.com/numeric/nl/nagdoc_27.1/flhtml/g05/g05tgf.html

Parameters
modeint

A code for selecting the operation to be performed by the function.

Set up reference vector only.

Generate variates using reference vector set up in a prior call to int_multinomial.

Set up reference vector and generate variates.

Generate variates without using the reference vector.

nint

, the number of pseudorandom numbers to be generated.

mint

, the number of trials of the multinomial distribution.

pfloat, array-like, shape

Contains the probabilities , for , of the possible outcomes of the multinomial distribution.

statecommdict, RNG communication object, modified in place

RNG communication structure.

This argument must have been initialized by a prior call to init_repeat() or init_nonrepeat().

commNone or dict, communication object, optional, modified in place

Communication structure for the reference vector.

If , this argument must have been initialized by a prior call to int_multinomial.

If , is not referenced and may be None.

Returns
xNone or int, ndarray, shape

The first rows of each contain pseudorandom numbers representing a -dimensional variate from the specified multinomial distribution.

Raises
NagValueError
(errno )

On entry, .

Constraint: , , or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, at least one element of the vector is less than or greater than .

(errno )

On entry, the sum of the elements of do not equal one.

(errno )

The value of or is not the same as when [‘r’] was set up in a previous call.

Previous value of and .

Previous value of and .

(errno )

On entry, some of the elements of the array [‘r’] have been corrupted or have not been initialized.

(errno )

On entry, [‘state’] vector has been corrupted or not initialized.

Notes

int_multinomial generates a sequence of groups of integers , for , for , from a multinomial distribution with trials and outcomes, where the probability of for each is

where

A single trial can have several outcomes () and the probability of achieving each outcome is known (). After trials each outcome will have occurred a certain number of times. The numbers representing the numbers of occurrences for each outcome after trials is then a single sample from the multinomial distribution defined by the parameters , and , for . This function returns such samples.

When this distribution is equivalent to the binomial distribution with parameters and (see int_binomial()).

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 int_multinomial with the same parameter values can then use this reference vector to generate further variates. The reference array is generated only for the outcome with greatest probability. The number of successes for the outcome with greatest probability is calculated first as for the binomial distribution (see int_binomial()); the number of successes for other outcomes are calculated in turn for the remaining reduced multinomial distribution; the number of successes for the final outcome is simply calculated to ensure that the total number of successes is .

One of the initialization functions init_repeat() (for a repeatable sequence if computed sequentially) or init_nonrepeat() (for a non-repeatable sequence) must be called prior to the first call to int_multinomial.

References

Knuth, D E, 1981, The Art of Computer Programming (Volume 2), (2nd Edition), Addison–Wesley