This repository provides a simple Python function make_cplx_spd_matrix that generates a random complex-valued, Hermitian, and positive semi-definite (PSD) covariance matrix.
This function is useful in scenarios involving complex-valued random variables, such as in signal processing and wireless communications.
The function make_cplx_spd_matrix creates a random Hermitian matrix by following these steps:
- Generates a random complex matrix
$A$ . - Computes the Singular Value Decomposition (SVD) of
$A^H A$ (where$A^H$ is the conjugate transpose of$A$ ). - Constructs a new matrix
$C$ using the SVD components and a random scaling matrix to ensure the resulting matrix is positive semi-definite.
The resulting matrix
- Python 3.x
numpy(for numerical operations)scipy(for linear algebra operations)
You can install the required packages with pip:
pip install numpy scipy# Function to generate a random complex PSD matrix
def make_cplx_spd_matrix(dim, rng=np.random.default_rng(1234567)):
# Generate a random complex matrix A
A = rng.random([dim, dim]) + 1j * rng.random([dim, dim])
# Perform Singular Value Decomposition (SVD) on A.T.conj() * A
U, _, Vt = scipy.linalg.svd(np.dot(A.T.conj(), A), check_finite=False)
# Construct the final matrix X using SVD components and random scaling
X = np.dot(np.dot(U, 1.0 + np.diag(rng.random(dim))), Vt)
# Return the complex PSD matrix
return Xdim: The dimension of the square matrix (i.e., the number of rows and columns).rng: The random number generator. By default, it usesnp.random.default_rng(1234567)for reproducibility.
- A complex-valued Hermitian positive semi-definite matrix of shape
(dim, dim).
There is a related function in the scikit-learn library: sklearn.datasets.make_spd_matrix. However, this function only generates real-valued symmetric matrices, not complex-valued Hermitian ones.
This project is licensed under the MIT License - see the LICENSE file for details.