Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé
Module « scipy.stats »

Fonction random_correlation - module scipy.stats

Signature de la fonction random_correlation

def random_correlation(eigs, seed=None, tol=1e-13, diag_tol=1e-07) 

Description

help(scipy.stats.random_correlation)

A random correlation matrix.

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
-------
rvs(eigs=None, random_state=None)
    Draw random correlation matrices, all with eigenvalues eigs.

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.

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.

References
----------

.. [1] Davies, Philip I; Higham, Nicholas J; "Numerically stable generation
       of correlation matrices and their factors", BIT 2000, Vol. 40,
       No. 4, pp. 640 651

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
array([[ 1.        , -0.02423399,  0.03130519,  0.4946965 ],
       [-0.02423399,  1.        ,  0.20334736,  0.04039817],
       [ 0.03130519,  0.20334736,  1.        ,  0.02694275],
       [ 0.4946965 ,  0.04039817,  0.02694275,  1.        ]])
>>> import scipy.linalg
>>> e, v = scipy.linalg.eigh(x)
>>> e
array([ 0.5,  0.8,  1.2,  1.5])



Vous êtes un professionnel et vous avez besoin d'une formation ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé