spey.helper_functions.correlation_to_covariance

spey.helper_functions.correlation_to_covariance#

spey.helper_functions.correlation_to_covariance(correlation_matrix: ndarray, standard_deviations: ndarray) ndarray[source]#

Convert correlation matrix into covariance matrix.

Computes \(\Sigma_{ij} = \sigma_i \rho_{ij} \sigma_j\) where \(\sigma_i\) are the per-bin standard deviations and \(\rho_{ij}\) is the input correlation matrix.

Parameters:
  • correlation_matrix (np.ndarray) – A real NxN correlation matrix \(\rho\) (diagonal entries equal to one, off-diagonals in [-1, 1]).

  • standard_deviations (np.ndarray) – A real N-dimensional vector of per-bin standard deviations \(\sigma_i\).

Returns:

Covariance matrix \(\Sigma\) of shape (N, N).

Return type:

np.ndarray

Example

>>> import numpy as np
>>> from spey.helper_functions import correlation_to_covariance
>>> rho = np.array([[1.0, 0.3], [0.3, 1.0]])
>>> sigma = np.array([2.0, 4.0])
>>> correlation_to_covariance(rho, sigma)
array([[ 4. ,  2.4],
       [ 2.4, 16. ]])