Loading [MathJax]/extensions/tex2jax.js
scipy 1.10.1 Pypi GitHub Homepage
Other Docs

MethodsNotesParametersRaisesReturns

Return a random correlation matrix, given a vector of eigenvalues.

The eigs keyword specifies the eigenvalues of the correlation matrix, and implies the dimension.

Methods

Notes

Generates a random correlation matrix following a numerically stable algorithm spelled out by Davies & Higham. This algorithm uses a single O(N) similarity transformation to construct a symmetric positive semi-definite matrix, and applies a series of Givens rotations to scale it to have ones on the diagonal.

Parameters

eigs : 1d ndarray

Eigenvalues of correlation matrix

seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional

If seed is None (or np.random), the numpy.random.RandomState singleton is used. If seed is an int, a new RandomState instance is used, seeded with seed. If seed is already a Generator or RandomState instance then that instance is used.

tol : float, optional

Tolerance for input parameter checks

diag_tol : float, optional

Tolerance for deviation of the diagonal of the resulting matrix. Default: 1e-7

Raises

RuntimeError

Floating point error prevented generating a valid correlation matrix.

Returns

rvs : ndarray or scalar

Random size N-dimensional matrices, dimension (size, dim, dim), each having eigenvalues eigs.

A random correlation matrix.

Examples

import numpy as np
from scipy.stats import random_correlation
rng = np.random.default_rng()
x = random_correlation.rvs((.5, .8, 1.2, 1.5), random_state=rng)
x
import scipy.linalg
e, v = scipy.linalg.eigh(x)
e
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

numpy.random.mtrand:RandomStatemtrand:RandomState

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/stats/_multivariate.py#3756
type: <class 'type'>
Commit: