# naginterfaces.library.rand.multivar_​normal¶

naginterfaces.library.rand.multivar_normal(sorder, mode12, n, xmu, c, comm, statecomm)[source]

multivar_normal sets up a reference vector and generates an array of pseudorandom numbers from a multivariate Normal distribution with mean vector and covariance matrix .

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

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

Parameters
sorderint

Determines the storage order of variates; the th variate is stored in if , and if , for , for .

mode12int

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 multivar_normal.

Set up reference vector and generate variates.

nint

, the number of random variates required.

xmufloat, array-like, shape

, the vector of means of the distribution.

cfloat, array-like, shape

The covariance matrix of the distribution. Only the upper triangle need be set.

commdict, communication object, modified in place

Communication structure for the reference vector.

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

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().

Returns
xNone or float, ndarray, shape

The array of pseudorandom multivariate Normal vectors generated by the function.

Two possible storage orders are available.

If then holds the th dimension for the th variate.

If this ordering is reversed and holds the th dimension for the th variate.

Raises
NagValueError
(errno )

On entry, .

Constraint: , or .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, the covariance matrix is not positive semidefinite to machine precision.

(errno )

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

Previous value of and .

(errno )

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

Notes

When the covariance matrix is nonsingular (i.e., strictly positive definite), the distribution has probability density function

where is the number of dimensions, is the covariance matrix, is the vector of means and is the vector of positions.

Covariance matrices are symmetric and positive semidefinite. Given such a matrix , there exists a lower triangular matrix such that . is not unique, if is singular.

multivar_normal decomposes to find such an . It then stores , and in the reference vector which is used to generate a vector of independent standard Normal pseudorandom numbers. It then returns the vector , which has the required multivariate Normal distribution.

It should be noted that this function will work with a singular covariance matrix , provided is positive semidefinite, despite the fact that the above formula for the probability density function is not valid in that case. Wilkinson (1965) should be consulted if further information is required.

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 multivar_normal.

References

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

Wilkinson, J H, 1965, The Algebraic Eigenvalue Problem, Oxford University Press, Oxford
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.8636325001716614, "perplexity": 1785.176238791135}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-39/segments/1631780057615.3/warc/CC-MAIN-20210925082018-20210925112018-00133.warc.gz"}