qml.kernels.flip_matrix

flip_matrix(K)[source]

Remove negative eigenvalues from the given kernel matrix by taking the absolute value.

This method keeps the eigenvectors of the matrix intact.

Parameters

K (array[float]) – Kernel matrix, assumed to be symmetric.

Returns

Kernel matrix with flipped negative eigenvalues.

Return type

array[float]

Reference:

This method is introduced in arXiv:2103.16774.

Example:

Consider a symmetric matrix with both positive and negative eigenvalues:

>>> K = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 2]])
>>> np.linalg.eigvalsh(K)
array([-1.,  1.,  2.])

We then can invert the sign of all negative eigenvalues of the matrix, obtaining non-negative eigenvalues only:

>>> K_flipped = qml.kernels.flip_matrix(K)
>>> np.linalg.eigvalsh(K_flipped)
array([1.,  1.,  2.])

If the input matrix does not have negative eigenvalues, flip_matrix does not have any effect.