matrix_ops.vectors_from_gram_matrix¶
Calculates the vectors associated to a Gram matrix.
Functions¶
|
Obtain the corresponding ensemble of states from the Gram matrix [1]. |
Module Contents¶
- matrix_ops.vectors_from_gram_matrix.vectors_from_gram_matrix(gram)¶
Obtain the corresponding ensemble of states from the Gram matrix [1].
The function attempts to compute the Cholesky decomposition of the given Gram matrix. If the matrix is positive definite, the Cholesky decomposition is returned. If the matrix is not positive definite, the function falls back to eigendecomposition.
Examples
# Example of a positive definite matrix:
>>> import numpy as np >>> from toqito.matrix_ops import vectors_from_gram_matrix >>> gram_matrix = np.array([[2, -1], [-1, 2]]) >>> vectors = vectors_from_gram_matrix(gram_matrix) >>> vectors [array([1.41421356, 0. ]), array([-0.70710678, 1.22474487])]
# Example of a matrix that is not positive definite:
>>> gram_matrix = np.array([[0, 1], [1, 0]]) >>> vectors = vectors_from_gram_matrix(gram_matrix) Matrix is not positive semidefinite. Using eigendecomposition as alternative. >>> vectors [array([0.70710678+0.j , 0. -0.70710678j]), array([0.70710678+0.j , 0. +0.70710678j])]
References
- Raises:
LinAlgError – If the Gram matrix is not square.
- Parameters:
gram (numpy.ndarray) – A square, symmetric matrix representing the Gram matrix.
- Returns:
A list of vectors (np.ndarray) corresponding to the ensemble of states.
- Return type:
list[numpy.ndarray]