Return a random correlation matrix, given a vector of eigenvalues.
The eigs keyword specifies the eigenvalues of the correlation matrix, and implies the dimension.
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.
Eigenvalues of correlation matrix
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.
Tolerance for input parameter checks
Tolerance for deviation of the diagonal of the resulting matrix. Default: 1e-7
Floating point error prevented generating a valid correlation matrix.
Random size N-dimensional matrices, dimension (size, dim, dim), each having eigenvalues eigs.
A random correlation matrix.
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
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.
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